在使用AFJSONRequestOperation时,遇到报错
2014-08-08 16:24:26.470 DownjoyGameNews[6210:90b] 320.000000, 568.000000 , 320.000000 548.000000
2014-08-08 16:24:26.566 DownjoyGameNews[6210:90b] erroe Error Domain=AFNetworkingErrorDomain Code=-1016 "Expected content type {(
"text/javascript",
"application/json",
"text/json"
)}, got text/html" UserInfo=0x10a80b8a0 {NSLocalizedRecoverySuggestion={
"title": "abc",
"platform": 1,
"id": 123,
"image": "http://baidu.com"
}, NSErrorFailingURLKey=http://api.news.d.cn/AdvertByJson.ashx/?name=%E5%AE%A2%E6%88%B7%E7%AB%AF%E6%8E%A8%E8%8D%90&platform=1, AFNetworkingOperationFailingURLRequestErrorKey=<NSMutableURLRequest: 0x10a801d70> { URL: http://api.news.d.cn/AdvertByJson.ashx/?name=%E5%AE%A2%E6%88%B7%E7%AB%AF%E6%8E%A8%E8%8D%90&platform=1 }, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x10aa0f110> { URL: http://api.news.d.cn/AdvertByJson.ashx/?name=%E5%AE%A2%E6%88%B7%E7%AB%AF%E6%8E%A8%E8%8D%90&platform=1 } { status code: 200, headers {
"Cache-Control" = private;
"Content-Length" = 86;
"Content-Type" = "text/html; charset=utf-8";
Date = "Fri, 08 Aug 2014 08:27:42 GMT";
Server = "Microsoft-IIS/6.0";
"X-AspNet-Version" = "2.0.50727";
"X-Powered-By" = "ASP.NET";
} }, NSLocalizedDescription=Expected content type {(
"text/javascript",
"application/json",
"text/json"
)}, got text/html}
意思是Error Domain=AFNetworkingErrorDomain Code=-1016,这个主要是因为By default, AFJSONRequestOperation accepts only "text/json", "application/json" or "text/javascript" content-types from server, but you are getting "text/html".
所以,Fixing on server would be better, but you can also add "text/html" content type as acceptable in your app
[AFJSONRequestOperation addAcceptableContentTypes:[NSSet setWithObject:@"text/html"]];