afnetworking 请求错误,2023-02-22

Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: image/gif" UserInfo={NSLocalizedDescription=Request failed: unacceptable content-type: image/gif,

此错误意思是不能接收的返回值类型: image/gif,即服务器返回了一个 image/gif类型的返回值。

出现原因为AFN本身不能接受这种类型,默认接收类型只有application/json,text/json,text/javascript三种。

解决方案:为AFN添加此接收类型:

AFHTTPSessionManager *manager=[AFHTTPSessionManager manager];

manager.reesponseSerializer.acceptableContentTypes = [NSSet setWithObjects: @"application/json", @"text/json", @"text/javascript",@"text/plain",@"image/gif",nil];

参考:https://www.jianshu.com/p/fedda77e27da

3840错误
Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option to allow fragments not set."

如上错误提示,是因为服务器返回数据不是正常的json数据,解析不了,

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容