AFN2.0请求报错-1016-3840解决办法

上传图片时出现了1016的错误,在网上查找解决方法如下:

在进行网络请求时出现-1016 是因为文档只支持 text/json,application/json,text/javascript 你可以添加text/html解决。

AFURLResponseSerialization.h里面搜索 self.acceptableContentTypes 然后在里面添加 @"text/html",@"text/plain"

这样就可以解决-1016的错误了,但是又出现了3840错误。

Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x9152780 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}

你会发现出现此错误,怎么办呢,添加如下语句 就可以解决问题了。

manger.requestSerializer = [AFHTTPRequestSerializer  serializer];

manger.responseSerializer = [AFHTTPResponseSerializer  serializer];

把收到的responseObject 转换一下 编码 就OK了

NSData *aaa = responseObject;

NSString *bbb =  [[NSString alloc]initWithData:doubi encoding:NSUTF8StringEncoding];

posted on 2015-11-17 10:38  懒猫君  阅读(286)  评论(0)    收藏  举报

导航