AFJSONRequestOperation一个错误

用AFNetWorking框架中的AFJSONRequestOperation下载json数据是一直出错。

打断点跟踪后发现,每次都没有走到success语法块里面,而是直接走到failure语法块里面。

我想把failure语法块里面的错误信息打印出来

[cpp]  view plain copy
  1. failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {  
  2.                 NSLog(@"failure:%@",[error description]);  
  3.             }  

输出的结果是这样的

[html]  view plain copy
  1. failure:Error Domain=AFNetworkingErrorDomain Code=-1016 "Expected content type {(  
  2.     "text/json",  
  3.     "application/json",  
  4.     "text/javascript"  
  5. )}, got text/html" UserInfo=0x84849d0 {NSLocalizedRecoverySuggestion={"message":["用户名为空!"],"data":[null],"success":false}, AFNetworkingOperationFailingURLRequestErrorKey=<NSURLRequest http://192.168.0.99:8080/jlsj/ios_mobileLogin.action?mobileUserName=A&mobilePassword=A>NSErrorFailingURLKey=http://192.168.0.99:8080/jlsj/ios_mobileLogin.action?mobileUserName=A&mobilePassword=ANSLocalizedDescription=Expected content type {(  
  6.     "text/json",  
  7.     "application/json",  
  8.     "text/javascript"  
  9. )}, got text/html, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x8443230>}  

原来是缺少它需要的字符集,于是在前面加上

[cpp]  view plain copy
  1. [AFJSONRequestOperation addAcceptableContentTypes:[NSSet setWithObjects:@"application/json", @"text/html", nil]];  
这下终于可以成功运行了。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值