If the response is type of NSHTTPURLResponse
you can get header from response.allHeaderFields
.
So when you use Alamofire responseJSON you can access to NSHTTPURLResponse property like this :
Alamofire.request(.GET, requestUrl, parameters:parameters, headers: headers).responseJSON {
response in
print(response.response?.allHeaderFields)
}
As apple documentation says :
A dictionary containing all the HTTP header fields received as part of the server’s response. By examining this dictionary clients can see the “raw” header information returned by the HTTP server.
The keys in this dictionary are the header field names, as received from the server. See RFC 2616 for a list of commonly used HTTP header fields.
So to get for example a content-type in response header you can access it in that way :
if let contentType = response.response?.allHeaderFields["Content-Type"] as? String {
// use contentType here
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…