标签:
当用AFN进行网络请求或者上传文件时,响应的报文无法接受、解析。会报如上错误。
那是因为服务器响应格式不被AFN支持,不是AFN操蛋,而是服务器返回格式不常规。
以下是两个解决方法:
1.操蛋的解决方法
AFURLResponseSerialization.m文件
223行:
self.acceptableContentTypes = [NSSetsetWithObjects:@"application/json", @"text/html",@"text/json",@"text/javascript", nil];
加上粗体部分,其实就是添加一种服务器返回的数据格式。
2.建议的解决方法
manager.serializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];
2与1相比最直接的好处是,简单温和,不修改第三方框架的代码,以后即便升级也不会带来问题
**************error信息****************
获取服务器响应出错 error=Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html" UserInfo=0x7fdfd8729680 {com.alamofire.serialization.response.error.response= { URL: http://172.16.1.31:7001/itom/getwork } { status code: 200, headers {
"Cache-Control" = "no-cache";
"Content-Type" = "text/html;charset=UTF-8";
Date = "Mon, 24 Nov 2014 03:13:16 GMT";
"Transfer-Encoding" = Identity;
"X-Powered-By" = "Servlet/2.5 JSP/2.1";
} }, NSErrorFailingURLKey=http://172.16.1.31:7001/itom/getwork, com.alamofire.serialization.response.error.data=<5b7b2273 74617475 73223a22 73756363 65737322 2c226d73 67223a22 e799bbe9 9986e688 90e58a9f 227d5d>, NSLocalizedDescription=Request failed: unacceptable content-type: text/html or text/plain}
AFN failed: unacceptable content-type: text/plain, com.alamofire.serialization
标签:
原文地址:http://www.cnblogs.com/xiubin/p/5036089.html