How to retrieve response headers with Alamofire in Swift?

Posted by Wei Xia on May 16, 2017 | Hits:


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.


The answer below is using Swift 3.

Alamofire.request(.GET, requestUrl, parameters:parameters, headers: headers).responseJSON {
        response in

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

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


This is the end of post