iOS AFNetworking “Request failed: unacceptable content-type: text/html”问题

使用AFNetworking出现报错:

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";
å

 

解决方法:

全工程搜索AFURLResponseSerialization.m文件

修改223行:

self.acceptableContentTypes =
[NSSetsetWithObjects:@"application/json", @"text/html",@"text/json",@"text/javascript", nil];

加上蓝色部分,其实就是添加一种服务器返回的数据格式。

亲测,好使。

时间: 2024-10-24 01:51:25

iOS AFNetworking “Request failed: unacceptable content-type: text/html”问题的相关文章

AFNetWorking Request failed: unacceptable content-type: text/html

今天写了一个快递查询的功能,使用的是AFNetWorking框架, 贴个代码: dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ NSDictionary *[email protected]{@"key": @"key",@"com": @"shentong",@"cno": @"76893

iOS 使用AFNetworking遇到异常 Request failed: unacceptable content-type: text/html

错误日志是: Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x7fc8b970eb70> { URL: http:

iOS 使用AFNetworking遇到错误 Request failed: unacceptable content-type: text/html

错误日志: Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x7f999be478d0> { URL: myUrlX

AFNetworking 遇到错误 Code=-1016 &quot;Request failed: unacceptable content-type: text/plain&quot;

在开发过程使用了AFNetworking库,版本2.x,先运行第一个官方例子(替换GET 后面的url即可): AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; [manager GET:@"http://example.com/resources.json" parameters:nil success:^(AFHTTPRequestOperation *operatio

iOS&quot;Request failed: unacceptable content-type: text/html&quot;

以前用的好端端的接口,今天访问居然出错了,但是再用浏览器测试,发现可以正常返回数据,甚是奇怪啊. 下面是错误信息: 获取服务器响应出错 error=ErrorDomain=com.alamofire.error.serialization.response Code=-1016"Request failed: unacceptable content-type: text/html"UserInfo=0x7fdfd8729680{com.alamofire.serialization.

AFNetworking 3.0.4 Error:&quot;Request failed: unacceptable content-type: text/html&quot;

使用AFNetWorking上传内容+参数, 1 NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:@"http://example.com/upload" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFor

iOS AFN请求返回错误:&quot;Request failed: unacceptable content-type: text/html&quot;

以前用的好端端的接口,今天访问居然出错了,但是再用浏览器测试,发现可以正常返回数据,甚是奇怪啊. 下面是错误信息: 获取服务器响应出错 error=Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html" UserInfo=0x7fdfd8729680 {com.alamofire.serializat

NSLocalizedDescription=Request failed: unacceptable content-type: text/html 解决方法

使用AFNetworking请求一个网站出现了以下错误 Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x7fc688f3

Error Domain=com.alamofire.error.serialization.response Code=-1016 &quot;Request failed: unacceptable content-type: text/html&quot; 的问题原因及解决方案

Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html",此问题的原因就是使用的第三方框架AFNetworking 接口返回值类型不确定,由于服务器人员习惯于使用html文件所以将json文件也这么写了,导致没法解析 在模型类或者网络工具类中添加这句代码就能完美解决上述问题,建议不要直接修改AFNetw