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.
Quite simply, since the accepted answer doesn't actually have an example:
[operationInstance setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"%@", operation.response.allHeaderFields);
}];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With