lix*_*lix 14 xcode objective-c afnetworking
我想弄清楚如何从AFNetworking请求中读取响应头?
是否可以在以下代码段中,或者我是否需要采取其他方法?
// 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){
}];
Bar*_*obs 37
完成此操作的最简单方法是使用成功和失败块中都可用的AFHTTPRequestOperation实例的响应属性(不是块的响应对象).
此响应对象是NSHTTPURLResponse的一个实例,您可以向其发送一条消息,   allHeaderFields以获取请求的所有标头.
很简单,因为接受的答案实际上没有一个例子:
[operationInstance setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
       NSLog(@"%@", operation.response.allHeaderFields);
}];