How to retrieve response headers with Alamofire in Swift?
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 | Alamofire.request(.GET, requestUrl, parameters:parameters, headers: headers).responseJSON { |
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