Reputation: 459
I have a POST method that on success redirects me on another page. In the final destination as result I have no set Cookies. How to retrieve cookies from first response? (Alamofire does autoredirect)
Alamofire.request( NSLocalizedString("url_login", comment: ""), method: .post, parameters: params).response{ response in
if let headerFields = response.response?.allHeaderFields as? [String: String],
let URL = response.request?.url
{
let cookies = HTTPCookie.cookies(withResponseHeaderFields: headerFields, for: URL)
print(cookies)
}
if response.response?.statusCode == 200 {
/.../
}else{
/..../
}
}
Upvotes: 1
Views: 286
Reputation: 27221
Just disable redirect and read the results. like this:
delegate.taskWillPerformHTTPRedirection = { _, _, _, _ in
return nil
}
Upvotes: 1