在开发过程使用了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,就可以了。

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

  1. AFNetworking request failed unacceptable content type text/html

    今天体验AFNetwork 3.1.0 进行数据解析,但是解析数据控制台一直都输出这样的 error 结果: 于是,照着以前AFN2.+版本的进行设置: 结果发现在新版本的 AFN 上不能设置了.既然 ...

  2. Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html"

    2015-11-16 10:39:17.235 PullDemo[338:60b] Application windows are expected to have a root view contr ...

  3. AFNetworking3.0出现Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable

    在发送请求后一直报错, 浏览器解析却没有问题, 所以基本可以确定是AFNetworking的问题 下面是解决方法: AFHTTPSessionManager *manager = [AFHTTPSes ...

  4. Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable con

    AFHTTPSessionManager * manager = [AFHTTPSessionManager manager]; manager.responseSerializer.acceptab ...

  5. iOS之AFN错误代码1016(Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable)

    请参考这篇博客:点击查看

  6. Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptabl

    在使用AFNetworking 2.0  的时候本来一切很顺畅,但是中途遇到几个比较坑的地方 这里分享一下爬坑经历,忘读者不能速爬坑! 在发送请求后,NSURLSessionDataTask一直报错 ...

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

    错误日志: Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacc ...

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

    使用AFNetworking出现报错: error=Error Domain=com.alamofire.error.serialization.response Code=-1016 "R ...

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

    错误日志是: Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unac ...

随机推荐

  1. UVa 1605 联合国大楼

    https://vjudge.net/problem/UVA-1605 题意:有n个国家,要求设计一栋楼并为这n个国家划分房间,要求国家的房间必须连通,且每两个国家之间必须有一间房间是相邻的. 思路: ...

  2. git连接华为开发云devcloud

    华为开发运在代码托管方面的个github很类似,引入了代码仓库的概念,同时需要本地安装git客户端,且只能与git进行连接,从这个角度上讲,华为开发云的代码管理部分就是github的功能,下面对git ...

  3. spoj MINSUB 单调栈+二分

    题目链接:点击传送 MINSUB - Largest Submatrix no tags  You are given an matrix M (consisting of nonnegative i ...

  4. 华中农业大学第四届程序设计大赛网络同步赛 G.Array C 线段树或者优先队列

    Problem G: Array C Time Limit: 1 Sec  Memory Limit: 128 MB Description Giving two integers  and  and ...

  5. 使用canvas画三角形

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. Jenkins + Ant + Jmeter 对项目的接口进行CI持续集成的配置 外加发送邮件 sendEmail

    Step1:安装Jenkins,从指定git上拉代码[安装步骤忽略] Step2:在项目安装的linux server上安装Ant 和Jmeter,我都安装在了自己的目录上,如下图 Step3:编写b ...

  7. netcat使用指南

    在网络工具中有“瑞士军刀”美誉的NetCat, 在我们用了N年了至今仍是爱不释手.因为它短小精悍(这个用在它身上很适合,现在有人已经将其修改成大约10K左右,而且功能不减少).现在就我的一些使用心得和 ...

  8. 2018年全国多校算法寒假训练营练习比赛(第一场)D N阶汉诺塔变形

    https://www.nowcoder.com/acm/contest/67/D 思路: 先手动模拟一下过程,以下是模拟过程,按顺序表示第几步需要移动的盘标号 1 1 2 1 1 2 1 1 3 1 ...

  9. telnet 命令使用方法详解,telnet命令怎么用?

    什么是Telnet? 对于Telnet的认识,不同的人持有不同的观点,可以把Telnet当成一种通信协议,但是对于入侵者而言,Telnet只是一种远程登录的工具.一旦入侵者与远程主机建立了Telnet ...

  10. Java注解 框架开发之Java注解的妙用

    原文出处: locality 注解的好处: 1.能够读懂别人写的代码,特别是框架相关的代码. 2.本来可能需要很多配置文件,需要很多逻辑才能实现的内容,就可以使用一个或者多个注解来替代,这样就使得编程 ...