I'm trying to figure out how to read the response headers from a AFNetworking request?
Is it possible in the following snippet, or do I need to take another approach?
// Create client
AFHTTPClient *client = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@"http://example.com/"]];
// Send request
[client getPath:@"/test" parameters:nil success:^(AFHTTPRequestOperation *operation, id response) {
} failure:^(AFHTTPRequestOperation *operation, NSError *error){
}];
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.