RestKit 0.20 Error Domain = org.restkit.RestKit.ErrorDomain Code =

编程入门 行业动态 更新时间:2024-10-25 21:23:32
RestKit 0.20 Error Domain = org.restkit.RestKit.ErrorDomain Code = -1016(RestKit 0.20 Error Domain=org.restkit.RestKit.ErrorDomain Code=-1016)

我正在尝试将RestKit 0.20集成到我的项目所以例如我正在使用谷歌rss阅读器进行示例项目。

这是Xml的响应 / / category>&

这是我必须获取数据的Xml。

RKObjectMapping * articleMapping = [RKObjectMapping mappingForClass:[News class]]; [articleMapping addAttributeMappingsFromDictionary:@ {@“title”:@“title”,@“link”:@“link”,@“guid”:@“guid”,@“pubDate”:@“pubDate”,@“description” :@“description”}];

NSURL* url = [[NSURL alloc]initWithString:@"http://news.google.com"]; RKObjectManager* objectManager = [RKObjectManager managerWithBaseURL:url]; NSURLRequest* request = [objectManager requestWithObject:nil method:RKRequestMethodGET path:@"/?output=rss" parameters:nil]; RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:articleMapping pathPattern:nil keyPath:@"item" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]; RKObjectRequestOperation *objectRequestOperation = [[RKObjectRequestOperation alloc] initWithRequest:request responseDescriptors:@[ responseDescriptor ]]; [objectRequestOperation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) { RKLogInfo(@"Load collection of Articles: %@", mappingResult.array); } failure:^(RKObjectRequestOperation *operation, NSError *error) { RKLogError(@"Operation failed with error: %@", error); }]; [objectRequestOperation start];

上面是我用来获取数据的代码当我运行应用程序时,我收到以下错误

我的restkit.network:RKObjectRequestOperation.m:174获取' http://news.google.com/?output=rss'2013-05-28 12:24:15.076 TestApp [8940:15203] E restkit.network:RKObjectRequestOperation。 m:569对象请求失败:基础HTTP请求操作失败,错误:错误Domain = org.restkit.RestKit.ErrorDomain Code = -1016“预期内容类型{(”application / xml“,”application / x-www-form- urlencoded“,”application / json“)},得到application / rss + xml”UserInfo = 0xa80a3d0 {NSLocalizedRecoverySuggestion = NFE / 1.0Top Stories - Google新闻

任何人都可以帮忙

I am trying to integrate RestKit 0.20 to My Project So for Example i am using google rss reader for sample project.

This is the response for Xml / /category> &

This is the Xml from where i have to get the data.

RKObjectMapping* articleMapping = [RKObjectMapping mappingForClass:[News class]]; [articleMapping addAttributeMappingsFromDictionary:@{ @"title": @"title", @"link": @"link", @"guid": @"guid", @"pubDate": @"pubDate", @"description": @"description" }];

NSURL* url = [[NSURL alloc]initWithString:@"http://news.google.com"]; RKObjectManager* objectManager = [RKObjectManager managerWithBaseURL:url]; NSURLRequest* request = [objectManager requestWithObject:nil method:RKRequestMethodGET path:@"/?output=rss" parameters:nil]; RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:articleMapping pathPattern:nil keyPath:@"item" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]; RKObjectRequestOperation *objectRequestOperation = [[RKObjectRequestOperation alloc] initWithRequest:request responseDescriptors:@[ responseDescriptor ]]; [objectRequestOperation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) { RKLogInfo(@"Load collection of Articles: %@", mappingResult.array); } failure:^(RKObjectRequestOperation *operation, NSError *error) { RKLogError(@"Operation failed with error: %@", error); }]; [objectRequestOperation start];

Above is the code i used to get data When i run the app i am getting the following error

I restkit.network:RKObjectRequestOperation.m:174 GET 'http://news.google.com/?output=rss' 2013-05-28 12:24:15.076 TestApp[8940:15203] E restkit.network:RKObjectRequestOperation.m:569 Object request failed: Underlying HTTP request operation failed with error: Error Domain=org.restkit.RestKit.ErrorDomain Code=-1016 "Expected content type {( "application/xml", "application/x-www-form-urlencoded", "application/json" )}, got application/rss+xml" UserInfo=0xa80a3d0 {NSLocalizedRecoverySuggestion=NFE/1.0Top Stories - Google News

Can any one help

最满意答案

正如例外所述,RestKit期待以下之一:

“应用程序/ xml” 的 “应用程序/ x WWW的形式进行了urlencoded” “应用程序/ JSON”

但它正在接收“application / rss + xml”。 你只需告诉RestKit会发生什么。

你可以问RestKit它是否已经理解了mime类型:

[RKMIMETypeSerialization registeredMIMETypes];

如果不是,则需要使用RKMIMETypeSerialization注册序列化RKMIMETypeSerialization 。

你可以告诉对象管理器期望的mime类型:

[objectManager setAcceptHeaderWithMIMEType:@"application/rss+xml"];

As the exception says, RestKit is expecting one of:

"application/xml" "application/x-www-form-urlencoded" "application/json"

But it's receiving "application/rss+xml". You just need to tell RestKit what to expect.

You can ask RestKit if it already understands the mime type:

[RKMIMETypeSerialization registeredMIMETypes];

If not you'll need to register a serializer with RKMIMETypeSerialization.

And you can tell the object manager what mime type to expect:

[objectManager setAcceptHeaderWithMIMEType:@"application/rss+xml"];

更多推荐

本文发布于:2023-07-04 11:10:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1023618.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Error   Domain   RestKit   ErrorDomain   Code

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!