使用AFNetworking 2.0时,“不可接受的内容类型:application / rss + xml”

时间:2013-11-07 08:16:07

标签: ios rss afnetworking-2

我想使用AFNetworking 2.0在此站点中获取RSS的XML数据:http://www.ifanr.com/feed 但我明白了:

Error: Error Domain=AFNetworkingErrorDomain Code=-1016 
"Request failed: unacceptable content-type: application/rss+xml" UserInfo=0x8c21d50 

{NSErrorFailingURLKey=http://www.ifanr.com/feed, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x8c14c90> { URL: http://www.ifanr.com/feed } { status code: 200, headers {
"Cache-Control" = "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
Connection = "keep-alive";
"Content-Encoding" = gzip;
"Content-Type" = "text/xml; charset=UTF-8";
Date = "Thu, 07 Nov 2013 08:07:29 GMT";
Expires = "Thu, 19 Nov 1981 08:52:00 GMT";
"Last-Modified" = "Thu, 07 Nov 2013 07:34:23 GMT";
Pragma = "no-cache";
Server = "nginx/1.5.6";
"Set-Cookie" = "ifanr_sidebar_showcase_index=3, PHPSESSID=i58cv75l1djp5gdrajn28qo8e5; path=/, liveblog-client-id=78878135; path=/";
"Transfer-Encoding" = Identity;
"X-Join-Us" = "http://jobboard.ifanr.com/, tifan <at> ifanr.com";
"X-Pingback" = "http://www.ifanr.com/xmlrpc.php";
"X-UA-Compatible" = "IE=Edge,chrome=1";
"X-XSS-Protection" = "1; mode=block";
} }, NSLocalizedDescription=Request failed: unacceptable content-type: application/rss+xml}

这是我的代码:

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager setResponseSerializer:[AFXMLParserResponseSerializer new]];
[manager GET:@"http://www.ifanr.com/feed" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"Data: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error: %@", error);
}];

出了什么问题?

2 个答案:

答案 0 :(得分:5)

我自己解决了这个问题。 只需添加以下语句:

manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"application/rss+xml"]
[manager setResponseSerializer:[AFXMLParserResponseSerializer new]];

答案 1 :(得分:2)

大卫就在这里,应该是其他方式

[manager setResponseSerializer:[AFXMLParserResponseSerializer new]];     
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"application/rss+xml"]