4

我想使用 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);
}];

有事吗?

4

2 回答 2

5

I have sloved this question by myself. simply add the following statements:

manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"application/rss+xml"]
[manager setResponseSerializer:[AFXMLParserResponseSerializer new]];
于 2013-11-08T08:45:35.013 回答
2

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

[manager setResponseSerializer:[AFXMLParserResponseSerializer new]];     
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"application/rss+xml"]
于 2014-01-31T15:20:55.710 回答