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: 0x7fc688f34d00> { URL: http://xxx.xxx.xxx }
{ status code: 200, headers {
    "Content-Encoding" = gzip;
    "Content-Type" = "text/html";
    Date = "Sat, 10 Oct 2015 13:44:28 GMT";
    Server = "nginx/1.4.1";
    Vary = "Accept-Encoding";
    "X-Cache" = "MISS from RJ-ZSBGP-CDN-75";
    "X-Powered-By" = "PHP/5.4.16";
} }, NSErrorFailingURLKey=http://xxx.xxx.xxx, com.alamofire.serialization.response.error.data=<7b227374 61746522 3a227375 63636573 73222c22 6d657373 61676522 3a22222c 22726573 756c7422 3a5b5d7d>, NSLocalizedDescription=Request failed: unacceptable content-type: text/html}

解决方法:

修改AFNetworking中AFURLResponseSerialization.m文件

在223行,将

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

改成

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

增加了一个 @"text/html"

如果你不是在wb145230博客园看到本文,请点击查看原文.

时间: 2024-12-29 11:58:13

NSLocalizedDescription=Request failed: unacceptable content-type: text/html 解决方法的相关文章

AFNetworking 2.0 获取json数据时,返回 NSLocalizedDescription=Request failed: unacceptable content-type: text/html, 解决方法.

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"]; 1:优先让服务器做好返回类型适配 2:服务器不做的话, 在程序中再加上上面的代码. 把类型加上.

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

报错:Request failed: unacceptable content-type: text/html

错误: (null) @"NSLocalizedDescription" : @"Request failed: unacceptable content-type: text/html" 原因: AFNetworking  默认不支持text/html AFURLResponseSerialization.m 源码  ->   self.acceptableContentTypes = [NSSet setWithObjects:@"applica

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

AFNetworking报错:(415 Domain=com.alamofire.error.serialization.response Code=-1011 &quot;Request failed: unsupported media type (415)&quot;)

问题? 今天在与后台调接口的时候,遇到一个问题,使用AFNetworking报错,具体如下: Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: unsupported media type (415)" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse:

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.

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