使用AFNetworking (2.2.3)遇到的问题

1、错误信息:Error:Error Domain=AFNetworkingErrorDomain Code=-1016 "Request failed: unacceptable content-type: text/html" UserInfo=0x16dcec00 {NSErrorFailingURLKey=http://www.weather.com.cn/data/sk/101110101.html, AFNetworkingOperationFailingURLResponseErrorKey= { URL: http://www.weather.com.cn/data/sk/101110101.html } { status code: 200, headers {
    Connection = "keep-alive";
    "Content-Encoding" = gzip;
    "Content-Type" = "text/html; charset=utf-8";
    Date = "Mon, 05 May 2014 09:40:27 GMT";
    Server = "Apache/2.2.0";
    "Transfer-Encoding" = Identity;
} }, NSLocalizedDescription=Request failed: unacceptable content-type: text/html}

原因:

AFNetworking  默认不支持text/html

AFURLResponseSerialization.m 源码  ->   self.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", nil];

解决办法:

1)在作者源代码处添加 @"text/html" 。

2)在自己的代码处加上这句代码:

 manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];


参考的资料:

http://www.cocoachina.com/bbs/simple/?t176000.html

http://www.cocoachina.com/ask/questions/show/108598

https://github.com/AFNetworking/AFNetworking/blob/master/README.md



你可能感兴趣的:(iOS开发笔记)