Reading AFNetworking response headers Reading AFNetworking response headers xcode xcode

Reading AFNetworking response headers


The easiest way to accomplish this is to use the response property (not the response object of the block) of the AFHTTPRequestOperation instance that is available in both the success and failure blocks.

This response object is an instance of NSHTTPURLResponse and you can send it a message of allHeaderFields to fetch all the headers of your request.


Quite simply, since the accepted answer doesn't actually have an example:

[operationInstance setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {       NSLog(@"%@", operation.response.allHeaderFields);}];


I was not able to resolve it by [[operation response] allHeaderFields] or operation.response.allHeaderFields , as it gave compilation error.

I just typecasted it to (NSDictionary *) and access the key values as

[[(NSDictionary *)operation valueForKey: @"response"] valueForKey: @"allHeaderFields"]