Reputation: 149
I'm trying to get the redirect link from my post request but after upgraded to alamofire 4.3.0 my delegate.taskWillPerformHTTPRedirection has never called. What I'm doing wrong?
I'm calling this way:
let sessionManager = Alamofire.SessionManager(configuration: URLSessionConfiguration.default)
let delegate: Alamofire.SessionDelegate = sessionManager.delegate
delegate.taskWillPerformHTTPRedirection = { session, task, response, request in
let headers = response.allHeaderFields
MYUrlConstant.redirectLocation = headers["Location"]! as! String
return URLRequest(url: URL(string: MYUrlConstant.redirectLocation)!)
}
Alamofire.request("http://test.com", method: .post, parameters: nil).responseJSON {}
Upvotes: 0
Views: 1140
Reputation: 149
My problem: has not used the declared manager to make a call who I expected the redirection. Example:
let sessionManager = Alamofire.SessionManager(configuration: URLSessionConfiguration.default)
let configuration = URLSessionConfiguration.default
manager = Alamofire.SessionManager(configuration: configuration)
let delegate: Alamofire.SessionDelegate = SessionDelegate.init()
manager!.delegate.taskWillPerformHTTPRedirection = { session, task, response, request in
let headers = response.allHeaderFields
let redirectLocation = headers["Location"]! as! String
return URLRequest(url: URL(string: redirectLocation)!)
}
//make your call with your manager delcared
manager!.request("url", method: .post, parameters: parameters).responseJSON {
}
Upvotes: 1