iOS AFN请求返回错误:"Request failed: unacceptable content-type: text/html"

错误:

2015-10-02 11:57:51.251 GetInformation[2172:112764] error: Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x7f960053f840> { URL: http://www.weather.com.cn/adat/sk/101010100.html } { status code: 200, headers {
    Connection = "keep-alive";
    "Content-Encoding" = gzip;
    "Content-Type" = "text/html; charset=utf-8";
    Date = "Fri, 02 Oct 2015 03:57:51 GMT";
    "Set-Cookie" = "SERVERID=70d53437f30a0d9176113b45e391ced0|1443758271|1443758271;Path=/";
    "Transfer-Encoding" = Identity;
    Vary = "Accept-Encoding";
} }, NSErrorFailingURLKey=http://www.weather.com.cn/adat/sk/101010100.html, com.alamofire.serialization.response.error.data=<7b227765 61746865 72696e66 6f223a7b 22636974 79223a22 e58c97e4 baac222c 22636974 79696422 3a223130 31303130 31303022 2c227465 6d70223a 2239222c 22574422 3a22e8a5 bfe58d97 e9a38e22 2c225753 223a2232 e7baa722 2c225344 223a2232 3425222c 22575345 223a2232 222c2274 696d6522 3a223130 3a333022 2c226973 52616461 72223a22 31222c22 52616461 72223a22 4a435f52 41444152 5f415a39 3031305f 4a42222c 226e6a64 223a22e6 9a82e697 a0e5ae9e e586b522 2c227179 223a2231 30313522 7d7d>, NSLocalizedDescription=Request failed: unacceptable content-type: text/html}

错误分析:  缺少一种类型: text/html

解决方式:

 

对应到自己的项目里面,我用的是AFNetworking这套网络请求包,需要改的是:

AFURLResponseSerialization.m文件

223行:

self.acceptableContentTypes = [NSSetsetWithObjects:@"application/json", @"text/html",@"text/json",@"text/javascript", nil];

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值