我正在尝试从我的帖子请求中获取重定向链接,但在升级到alamofire 4.3.0之后,我的delegate.taskWillPerformHTTPRedirection从未调用过。 我做错了什么?
我这样称呼:
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 {}
答案 0 :(得分:1)
我的问题:没有使用声明的管理员拨打我期望重定向的电话。 例如:
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 {
}