错误:
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];
加上蓝色部分,其实就是添加一种服务器返回的数据格式。