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,就可以了。
AFNetworking 遇到错误 Code=-1016 "Request failed: unacceptable content-type: text/plain"的更多相关文章
- AFNetworking request failed unacceptable content type text/html
今天体验AFNetwork 3.1.0 进行数据解析,但是解析数据控制台一直都输出这样的 error 结果: 于是,照着以前AFN2.+版本的进行设置: 结果发现在新版本的 AFN 上不能设置了.既然 ...
- 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 ...
- AFNetworking3.0出现Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable
在发送请求后一直报错, 浏览器解析却没有问题, 所以基本可以确定是AFNetworking的问题 下面是解决方法: AFHTTPSessionManager *manager = [AFHTTPSes ...
- Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable con
AFHTTPSessionManager * manager = [AFHTTPSessionManager manager]; manager.responseSerializer.acceptab ...
- iOS之AFN错误代码1016(Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable)
请参考这篇博客:点击查看
- Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptabl
在使用AFNetworking 2.0 的时候本来一切很顺畅,但是中途遇到几个比较坑的地方 这里分享一下爬坑经历,忘读者不能速爬坑! 在发送请求后,NSURLSessionDataTask一直报错 ...
- iOS 使用AFNetworking遇到错误 Request failed: unacceptable content-type: text/html
错误日志: Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacc ...
- iOS AFNetworking “Request failed: unacceptable content-type: text/html”问题
使用AFNetworking出现报错: error=Error Domain=com.alamofire.error.serialization.response Code=-1016 "R ...
- iOS 使用AFNetworking遇到异常 Request failed: unacceptable content-type: text/html
错误日志是: Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unac ...
随机推荐
- bootstrap datarangepicker如何使用
本文为博主原创,未经允许不得转载: 下载资源文件: 地址:Github:https://github.com/dangrossman/bootstrap-daterangepicker/ 1.页面引用 ...
- LA 4329 乒乓比赛
https://vjudge.net/problem/UVALive-4329 题意: 一条大街上住着n个兵乓球爱好者,经常组织比赛切磋技术.每个人都有一个不同的技能值ai.每场比赛需要3个人:两名选 ...
- Spring 入门 web.xml配置详解
Spring 入门 web.xml配置详解 https://www.cnblogs.com/cczz_11/p/4363314.html https://blog.csdn.net/hellolove ...
- 《剑指offer》第三十五题(复杂链表的复制)
// 面试题35:复杂链表的复制 // 题目:请实现函数ComplexListNode* Clone(ComplexListNode* pHead),复 // 制一个复杂链表.在复杂链表中,每个结点除 ...
- 理解Fragment的生命周期
与活动类似,Fragment也有自己的生命周期.理解Fragment的生命周期有助于在Fragment销毁时能恰当地保存其实例,然后在重新创建时能够将其恢复至之前的状态. 下面的“试一试”将研究Fra ...
- Codeforces 893E - Counting Arrays
893E - Counting Arrays 思路:质因子分解. 对于每个质因子,假设它有k个,那么求把它分配到y个数上的方案数. 相当于把k个小球分配到y个盒子里的方案数. 这个问题可以用隔板法(插 ...
- LeetCode--111--最长公共前缀
问题描述: 给定一个二叉树,找出其最小深度. 最小深度是从根节点到最近叶子节点的最短路径上的节点数量. 说明: 叶子节点是指没有子节点的节点. 示例: 给定二叉树 [3,9,20,null,null, ...
- 我的Java学习笔记-Java面向对象
今天来学习Java的面向对象特性,由于与C#的面向对象类似,不需详细学习 一.Java继承 继承可以使用 extends 和 implements 这两个关键字来实现继承. extends:类的继承是 ...
- Jamie and Binary Sequence (changed after round) CodeForces - 916B (贪心)
链接 大意: 求将n划分为k个2的幂的和, 且最大幂最小,字典序尽量大 比较简单的贪心练习题, 但放在div2的B题感觉偏难了..... 先只考虑最大幂最小, 首先注意到直接按n的二进制划分即可得到最 ...
- poj3080kmp或者暴力
The Genographic Project is a research partnership between IBM and The National Geographic Society th ...