我正在使用新版本的AFNetworking,我不知道如何读取响应的标题.
我使用AFHTTPSessionManager来执行我的查询,一切都很好,但是我无法找到标题响应字段.
我使用AFHTTPSessionManager来执行我的查询,一切都很好,但是我无法找到标题响应字段.
这是我如何进行
self.sessionManager = [[AFHTTPSessionManager alloc] initWithBaseURL:[NSURL URLWithString:BASE_URL]];
[self.sessionManager GET:urlId parameters:nil
success:^(NSURLSessionDataTask *task,id responSEObject) {
if ([self.delegate respondsToSelector:@selector(userIsLoadedWithInfos:)]) {
[self.delegate userIsLoadedWithInfos: responSEObject];
}
} failure:^(NSURLSessionDataTask *task,NSError *error) {
if ([self.delegate respondsToSelector:@selector(userLoadingFailed)]) {
[self.delegate userLoadingFailed];
}
}
];
我尝试读取任务的响应属性,但它返回一个不包含头的NSURLResponse.
现在有人现在读取2.0版本的响应头吗?谢谢
解决方法
你试图从NSURLResponse获取头文件是返回的,
您可以尝试像NSURLResponse对象,
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
if ([httpResponse respondsToSelector:@selector(allHeaderFields)]) {
NSDictionary *dictionary = [httpResponse allHeaderFields];
NSLog([dictionary description]);
}
希望这将帮助你!