AFHTTPSessionManager status code

AFNetworking 3.0 使用 AFHTTPSessionManager 如何获得 http 的响应状态码

AFHTTPSessionManager status code AFNetworking 3.0

在获取的 task时 的 task.response 类型为NSURLResponse此类不包含http的回复状态码 需要向上类型转换将其转为他的子类 NSHTTPURLResponse,NSHTTPURLResponse包含状态码。


    [manager POST:User_login_url parameters:dic success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            NSError *errorForJSON = [NSError errorWithDomain:@"请求数据解析为json格式,发出错误" code:2014 userInfo:@{@"请求数据json解析错误": @"中文",@"serial the data to json error":@"English"}];
            NSLog(@"responseObject is %@", responseObject);
        NSLog(@"the responseObject class is %@", [responseObject class]);
        NSDictionary *responsedic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        
        NSHTTPURLResponse *urlResponse = (NSHTTPURLResponse *)task.response;
        NSLog(@"the response state code is %ld", (long)urlResponse.statusCode);
        
        NSLog(@"the responseDic is %@", responsedic);
        
//        task.response
        
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            NSLog(@"the task is %@", task);
            
            NSHTTPURLResponse *urlResponse = (NSHTTPURLResponse *)task.response;
            NSLog(@"the response state code is %ld", (long)urlResponse.statusCode);
            
            NSLog(@"error is %@", error.description);
        }];
    }];


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值