iOS"Request failed: unacceptable content-type: text/html"
接口访问出错了,用浏览器测试,发现可以正常返回数据.
下面是错误信息:
获取服务器响应出错 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";
} }, NSErrorFailingURLKey=http://172.16.1.31:7001/itom/getwork, com.alamofire.serialization.response.error.data=<5b7b2273 74617475 73223a22 73756363 65737322 2c226d73 67223a22 e799bbe9 9986e688 90e58a9f 227d5d>, NSLocalizedDescription=Request failed: unacceptable content-type: text/html}
I also encountered the same problem.
This means that your server is
sending "text/html" instead
of the already supported types. After a little search, my solution
was to
add "text/html" to acceptableContentTypes set
in AFURLResponseSerialization class.
Just search for "acceptableContentTypes" and
add @"text/html" to
the set manually. Of course, the ideal solution will be to change
the tpe from the server, but for that you will hade to talk with
the server team.
I hope this helps you. Best regards and
less bugs as possible in the code.
op.responseSerializer.acceptableContentTypes =
[NSSet setWithObject:@"text/html”];
对应到自己的项目里面,我用的是AFNetworking这套网络请求包,需要改的是:
AFURLResponseSerialization.m文件
223行:
self.acceptableContentTypes =
[NSSetsetWithObjects:@"application/json", @"text/html",@"text/json",@"text/javascript", nil];
加上蓝色部分,其实就是添加一种服务器返回的数据格式。
iOS"Request failed: unacceptable content-type: text/html"的更多相关文章
- AFNetworking request failed unacceptable content type text/html
今天体验AFNetwork 3.1.0 进行数据解析,但是解析数据控制台一直都输出这样的 error 结果: 于是,照着以前AFN2.+版本的进行设置: 结果发现在新版本的 AFN 上不能设置了.既然 ...
- 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 ...
- AFNetworking遇到错误 Request failed: unacceptable content-type: text/html
iOS 使用AFNetworking遇到错误 Request failed: unacceptable content-type: text/html 原因: 不可接受的内容类型 “text/html ...
- 使用AFNetworking 2.0 请求数据时出现错误 Request failed: unacceptable content-type: text/html 解决方法
使用AFNetworking 2.0 请求数据时出现错误 Request failed: unacceptable content-type: text/html 解决方法 添加一行 manager. ...
- 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 ...
- AFNetworking 遇到错误 Code=-1016 "Request failed: unacceptable content-type: text/plain"
在开发过程使用了AFNetworking库,版本2.x,先运行第一个官方例子(替换GET 后面的url即可): AFHTTPRequestOperationManager *manager = [AF ...
- NSLocalizedDescription=Request failed: unacceptable content-type: text/html 解决方法
使用AFNetworking请求一个网站出现了以下错误 Error Domain=com.alamofire.error.serialization.response Code=- "Req ...
随机推荐
- Gson--Gson解析=等号出现乱码?
GSON使用笔记(1) -- 序列化时排除字段的几种方式 --3,关于Gson解析时候特殊符号,被转义的问题,如'单引号? //Creating the JSON object, and gettin ...
- 学习C++的第三天
1.sort函数(默认升序排序(从小到大)) 要使用此函数只需用#include <algorithm> sort即可使用,语法描述为: sort(begin,end),表示一个 ...
- mysql重复记录的查询删除方法
1.查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断select * from peoplewhere peopleId in (select peopleId from ...
- IOS ScrollView放大缩小点击位置并居中
项目中的一个优化案例,提升用户体验,对地铁线路图点击放大.缩小,并且点击位置居中: 正常ScrollView 我们点击某一点比如屏幕右侧,想要点的位置向左移动到中心位置,很简单只有算出该点位置距中心位 ...
- vs2010下C++调用lib或dll文件
注: DLL:表示链接库,包含dll,lib文件: dll: 表示my.dll文件 lib: 表示my.lib文件 C++ 调用.lib的方法: 一: 隐式的加载时链接,有三种方法 1 设置工程的 ...
- jquery中获取元素的几种方式小结
1 从集合中通过指定的序号获取元素 html: 复制代码代码如下: <div> <p>0</p> <p>1</p> <p>2&l ...
- JavaScript的toString()和valueof()方法
toString()方法: 函数:函数 (function(){}).toString(); //返回"function(){}" typeof((function(){}).to ...
- css 画基本图形
抄于http://dongtianee.sinaapp.com/demo9.html /******************************************************** ...
- C++设计模式-Decorator装饰模式
Decorator装饰模式作用:动态地给一个对象添加一些额外的职责,就增加功能来说,装饰模式比生成子类更为灵活. UML图如下: Component是定义一个对象接口,可以给这些对象动态地添加职责. ...
- MonkeyRunner测试一MonkeyRunner的使用
最近搭建MonkeyRunner开发环境,安装PyDev时,饱受折磨,现在终于搞定.因为一些原因,用了JDK1.6,在线安装插件PyDev成功后,Windows-Preferences里找不到PyDe ...