ios – AFNetworking 2.0 //如何读取响应标题

我正在使用新版本的AFNetworking,我不知道如何读取响应的标题.
我使用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]);
}

希望这将帮助你!

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...