標籤:
ref:http://blog.csdn.net/nyh1006/article/details/25068255
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=<NSHTTPURLResponse: 0x16d5deb0> { 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"];
缺什麼類型就填那種類型,比如我是 text/plain
參考的資料:
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
AFNetworking content type not support