简体   繁体   English

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

[英]“unacceptable content-type: application/rss+xml” when using AFNetworking 2.0

I want to use AFNetworking 2.0 to get the XML data of RSS in this site : http://www.ifanr.com/feed but I get this : 我想使用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}

And here is my code : 这是我的代码:

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);
}];

something wrong? 有问题?

I have sloved this question by myself. 我自己解决了这个问题。 simply add the following statements: 只需添加以下语句:

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

David is right here, should be other way around 大卫就在这里,应该是其他方式

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AFNetworking 2.0 - “不可接受的内容类型:text / plain” - AFNetworking 2.0 - “unacceptable content-type: text/plain” 请求失败:不可接受的内容类型:使用AFNetworking 2.0的文本/纯文本 - Request failed: unacceptable content-type: text/plain using AFNetworking 2.0 使用AFNetworking 2.0的“请求失败:不可接受的内容类型:text / html” - “Request failed: unacceptable content-type: text/html” using AFNetworking 2.0 请求失败:不可接受的内容类型:使用AFNetworking 2.0的text / html - Request failed: unacceptable content-type: text/html using AFNetworking 2.0 AFNetworking请求失败:不可接受的内容类型:text / html - AFNetworking Request failed: unacceptable content-type: text/html AFNetworking 请求失败:不可接受的内容类型:文本/纯文本, - AFNetworking Request failed: unacceptable content-type: text/plain, 请求失败:不可接受的内容类型:使用AFNetworking 2.5的图像/ jpg - Request failed: unacceptable content-type: image/jpg using AFNetworking 2.5 请求失败:不可接受的内容类型:application / osm3s + xml - Request failed: unacceptable content-type: application/osm3s+xml 具有文本/纯文本响应的API失败,显示“内容类型不可接受” - API with text/plain response failed with 'unacceptable content-type' 请求失败:不可接受的内容类型:文本/纯文字-AFNetwork POST - Request failed: unacceptable content-type: text/plain - AFNetwork POST
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM