gpt4 book ai didi

ios - 使用 AFNetworking 2.0 时为 "unacceptable content-type: application/rss+xml"

转载 作者:可可西里 更新时间:2023-11-01 05:21:55 27 4
gpt4 key购买 nike

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

有什么问题吗?

最佳答案

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

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

关于ios - 使用 AFNetworking 2.0 时为 "unacceptable content-type: application/rss+xml",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19830882/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com