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

在开发过程使用了AFNetworking库,版本2.x,先运行第一个官方例子(替换GET 后面的url即可):

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:@"http://example.com/resources.json" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error: %@", error);
}];提示Error,但其实返回的是200 OK。Error: Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/plain" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x100438a90> { URL: http://testadmin.test.com/webservice/test } { status code: 200, headers {    Connection = "Keep-Alive";    "Content-Encoding" = gzip;    "Content-Length" = 61;    "Content-Type" = "text/plain";    Date = "Mon, 22 Feb 2016 09:19:32 GMT";    "Keep-Alive" = "timeout=10, max=10000";    Server = "SNMW1.0";    Vary = "Accept-Encoding";} }, NSErrorFailingURLKey=http://testadmin.test.com/webservice/test,

经过查资料,是默认的AFNetworking库,不支持解析 text/plain 类型,需要简单修改源代码就可以。打开AFURLResponseSerialization.m,找到类 AFJSONResponseSerializer,修改它的init函数:原内容:- (instancetype)init {    self = [super init];    if (!self) {        return nil;    }

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

修改为:- (instancetype)init {    self = [super init];    if (!self) {        return nil;    }

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

其实就是增加了text/plain,就可以了。
时间: 2025-01-05 03:10:56

AFNetworking 遇到错误 Code=-1016 "Request failed: unacceptable content-type: text/plain"的相关文章

[原]Error Domain=com.alamofire.error.serialization.response Code=-1016 &quot;Request failed: unacceptable con

转载请注明出处:http://blog.csdn.net/dengbin9009/article/details/43485617 在使用AFNetworking 2.0  的时候本来一切很顺畅,但是中途遇到几个比较坑的地方 这里分享一下爬坑经历,忘读者不能速爬坑! 在发送请求后,NSURLSessionDataTask一直报错 Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed:

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

Error Domain=com.alamofire.error.serialization.response Code=-1016 &quot;Request failed: unacceptable con

AFHTTPSessionManager * manager = [AFHTTPSessionManager manager]; manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json",@"text/javascript",@"text/html",nil];

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

Error Domain=com.alamofire.error.serialization.response Code=-1016 &quot;Request failed: unacceptabl

在使用AFNetworking 2.0  的时候本来一切很顺畅,但是中途遇到几个比较坑的地方 这里分享一下爬坑经历,忘读者不能速爬坑! 在发送请求后,NSURLSessionDataTask一直报错 Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html" AFURLResponseSerializat

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 使用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

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

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.1