接口访问出错了,用浏览器测试,发现可以正常返回数据.

下面是错误信息:

获取服务器响应出错 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"的更多相关文章

  1. AFNetworking request failed unacceptable content type text/html

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

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

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

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

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

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

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

  5. AFNetworking遇到错误 Request failed: unacceptable content-type: text/html

    iOS 使用AFNetworking遇到错误 Request failed: unacceptable content-type: text/html 原因: 不可接受的内容类型 “text/html ...

  6. 使用AFNetworking 2.0 请求数据时出现错误 Request failed: unacceptable content-type: text/html 解决方法

    使用AFNetworking 2.0 请求数据时出现错误 Request failed: unacceptable content-type: text/html 解决方法 添加一行 manager. ...

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

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

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

  9. NSLocalizedDescription=Request failed: unacceptable content-type: text/html 解决方法

    使用AFNetworking请求一个网站出现了以下错误 Error Domain=com.alamofire.error.serialization.response Code=- "Req ...

随机推荐

  1. XPath Checker和Firebug安装与使用

    一.XPath Checker和Firebug简介 XPath Checker和Firebug是写爬虫过程中提取数据的非常有用的插件工具,直接打开火狐浏览器的菜单就可以下载 二.XPath Check ...

  2. Kafka集群配置说明

    #kafka数据的存放地址,多个地址的话用逗号分 log.dirs=/tmp/kafka-logs #broker server服务端口 port=9092 #这个参数会在日志segment没有达到l ...

  3. caffe.exe (caffe.bin)用法回顾

    caffe.bin :command line brew usage : caffe  <command><args> commands: train:  训练或者微调一个网络 ...

  4. SQLSERVER分页查询

    转:http://blog.csdn.net/qiaqia609/article/details/41445233   Sqlserver数据库分页查询一直是Sqlserver的短板,   第一种方案 ...

  5. fish药品使用说明

    大白片Octozin的官方的使用方法首先换水1/3-1/2.第一天:开始下药(每22.5升水下1片药)第二天:继续下药(每22.5升水下1片药)第三天:还是下药(每22.5升水下1片药)也就是每天下同 ...

  6. SQL Server 2008 R2企业版开发版等版本下载 (转载)

    一. 简体中文 1. SQL Server 2008 R2 Developer (x86, x64, ia64) - DVD (Chinese-Simplified) File Name: cn_sq ...

  7. 转 nutch网页快照乱码解决方法

    修改apache-tomcat-7.0.55\webapps\nutch-1.2下的cached.jsp 将content = new String(bean.getContent(details)) ...

  8. System.Threading.Timer 定时器的用法

    System.Threading.Timer 是C# 中的一个定时器,可以定时(不断循环)执行一个任务.它是在线程上执行的,具有很好的安全性.为此  .Net Framework 提供了5个重载的构造 ...

  9. nodejs在同一台服务器上部署并同时运行两个或以上服务端时,一个服务用户登录后会挤掉另一个用户的问题

    问题描述:一台服务器,部署了两个或以上不同的Web服务,服务A的用户在登陆后,服务B的用户也登陆,此时服务A的用户在点击页面时,会返回登陆页面. 问题根源:浏览器保存的session相同,即cooki ...

  10. jQuery 插件基础

    jQuery 插件基础 翻译 How to Create a Basic Plugin 如果你需要在 jQuery 选择器上执行一系列重复操作, 这时候你需要编写 jQuery 插件. jQuery ...