Question

I’m using Alamofire to send a request to API, and API will send a reponse with headers. How can I retrive headers from it.

Answer

The answer below is using Swift 3.

1
2
3
4
Alamofire.request(.GET, requestUrl, parameters:parameters, headers: headers).responseJSON {
response in
print(response.response?.allHeaderFields)
}

response.response?.allHeaderFields contains all headers from the response.

If you want to get a certain value from headers, use response.response?.allHeaderFields[value] to get that header.

Reference


This is the end of post