iOS"Request failed: unacceptable content-type: text/html"

以前用的好端端的接口,今天访问居然出错了,但是再用浏览器测试,发现可以正常返回数据,甚是奇怪啊。

下面是错误信息:

获取服务器响应出错error=ErrorDomain=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 issending"text/html"insteadof the already supported types. After a little search, my solutionwas toadd"text/html"toacceptableContentTypessetinAFURLResponseSerializationclass.Just search for "acceptableContentTypes" andadd@"text/html"tothe set manually. Of course, the ideal solution will be to changethe tpe from the server, but for that you will hade to talk withthe 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];

加上斜体部分,其实就是添加一种服务器返回的数据格式。

原文来自:http://blog.sina.com.cn/s/blog_62f189570102va6j.html
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
javax.net.ssl.SSLHandshakeException: Unacceptable certificate错误是由于访问的域名证书不在有效期内或者JDK中不存在该证书的信任导致的。解决这个问题的方法有以下几种: 1. 更新JDK信任库:可以通过更新JDK的信任库来解决该问题。可以使用以下命令将证书添加到信任库中: ```shell keytool -import -alias <alias> -keystore <path_to_truststore> -file <path_to_certificate> ``` 其中,`<alias>`是证书的别名,`<path_to_truststore>`是信任库的路径,`<path_to_certificate>`是证书的路径。 2. 忽略证书验证:在某些情况下,可以选择忽略证书验证来解决该问题。可以通过以下代码来实现: ```java TrustManager[] trustAllCerts = new TrustManager[]{ new X509TrustManager() { public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; } public void checkClientTrusted( java.security.cert.X509Certificate[] certs, String authType) { } public void checkServerTrusted( java.security.cert.X509Certificate[] certs, String authType) { } } }; SSLContext sc = SSLContext.getInstance("TLS"); sc.init(null, trustAllCerts, new java.security.SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); ``` 3. 添加自定义信任证书:如果访问的是自签名证书或者不受信任的证书,可以将该证书添加到信任库中。可以使用以下命令将证书添加到信任库中: ```shell keytool -import -alias <alias> -keystore <path_to_truststore> -file <path_to_certificate> ``` 其中,`<alias>`是证书的别名,`<path_to_truststore>`是信任库的路径,`<path_to_certificate>`是证书的路径。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值