AFNetWorking 请求报错 text/html

2017-05-23 17:29:26.146 网络Test[95818:11935638] 失败:Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html"

UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x6000000327c0> { URL: http://mobile.weather.com.cn/data/zsM/101010100.html?_=1381891661502&pwd=520it } { status code: 200, headers {

    Connection = "keep-alive";

    "Content-Encoding" = gzip;

    "Content-Type" = "text/html; charset=utf-8";

    Date = "Tue, 23 May 2017 09:03:35 GMT";

    Server = "Apache/2.2.23";

    "Transfer-Encoding" = Identity;

} }, NSErrorFailingURLKey=http://mobile.weather.com.cn/data/zsM/101010100.html?_=1381891661502&pwd=520it, com.alamofire.serialization.response.error.data=https://my.oschina.net/u/2472425/blog/<7b226461 7465223a 22323031 33313031 32222c22 7a73223a 5b7b226e 616d6522 3a22e7a9 bae8b083 e5bc80e5 90afe68c 87e695b0 222c2268 696e7422 3a22e8be 83e5b091 e5bc80e5 90af222c 22646573 223a22e6 82a8e5b0 86e6849f e588b0e5 be88e888 92e98082 efbc8ce4 b880e888 ace4b88d e99c80e8 a681e5bc 80e590af e7a9bae8 b083e380 82227d2c 7b226e61 6d65223a 22e681af e696afe6 958fe8bf 87e6958f e68c87e6 95b0222c 2268696e 74223a22 e4b88de6 9893e58f 91222c22 64657322 3a22e5a4 a9e6b094 e69da1e4 bbb6e4b8 8de69893 e8afb1e5 8f91e8bf 87e6958f efbc8ce5 8fafe694 bee5bf83 e5a496e5 87baefbc 8ce999a4 e789b9e6 ae8ae4bd 93e8b4a8 e5a496ef bc8ce697 a0e99c80 e68b85e5 bf83e8bf 87e6958f e997aee9 a298e380 82227d2c 7b226e61 6d65223a 22e699a8 e7bb83e6 8c87e695 b0222c22 68696e74 223a22e9 8082e5ae 9c222c22 64657322 3a22e5a4 a9e6b094 e4b88de9 9499efbc 8ce7a9ba e6b094e6 b885e696 b0efbc8c e698afe6 82a8e699 a8e7bb83 e79a84e5 a4a7e5a5 bde697b6 e69cbaef bc8ce5bb bae8aeae e4b88de5 908ce5b9 b4e9be84 e6aeb5e7 9a84e4ba bae4bbac e7a7afe6 9e81e58f 82e58aa0 e688b7e5 a496e581 a5e8baab e6b4bbe5 8aa8e380 82227d2c 7b226e61 6d65223a 22e69785 e6b8b8e6 8c87e695 b0222c22 68696e74 223a22e9 8082e5ae 9c222c22 64657322 3a22e5a4 a9e6b094 e8be83e5 a5bdefbc 8ce4bd86 e4b89de6 afabe4b8 8de4bc9a e5bdb1e5 938de682 a8e587ba e8a18ce7 9a84e5bf 83e68385 e38082e6 b8a9e5ba a6e98082 e5ae9ce5 8f88e69c 89e5beae e9a38ee7 9bb8e4bc b4efbc8c e98082e5 ae9ce697 85e6b8b8 e3808222 7d2c7b22 6e616d65 223a22e7 b4abe5a4 96e7babf e5bcbae5 baa6e68c 87e695b0 222c2268 696e7422 3a22e5bc b1222c22 64657322 3a22e7b4 abe5a496 e7babfe5 bcbae5ba a6e8be83 e5bcb1ef bc8ce5bb bae8aeae e587bae9 97a8e589 8de6b682 e693a653 5046e59c a831322d 3135e4b9 8be997b4 e3808150 412be79a 84e998b2 e69992e6 8aa4e882 a4e59381 e3808222 7d5d7d>, NSLocalizedDescription=Request failed: unacceptable content-type: text/html}

 

 

原因:
不接受的内容类型 “text/html

 

解决方案
AFURLResponseSerialization.m 中
把 这句:     self.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/Javascript", nil];
修改为:
self.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil];

 

赞 (0) 评论 分享 ()