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

时间:2013-05-28 07:37:05

标签: ios objective-c restkit-0.20

我正在尝试将RestKit 0.20集成到My Project所以例如我正在使用google rss reader进行示例项目。

这是Xml的响应                       
           /                          /类别>                         &安培;          

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

RKObjectMapping * articleMapping = [RKObjectMapping mappingForClass:[News class]];     [articleMapping addAttributeMappingsFromDictionary:@ {      @“title”:@“title”,      @“链接”:@“链接”,      @“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“预期内容类型{(     “应用程序/ xml” 的,     “应用程序/ x WWW的形式进行了urlencoded”,     “应用程序/ JSON” 得到application / rss + xml“UserInfo = 0xa80a3d0 {NSLocalizedRecoverySuggestion = NFE / 1.0Top Stories - Google News

任何人都可以提供帮助

1 个答案:

答案 0 :(得分:4)

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

  1. "应用/ XML"
  2. "应用程序/ X WWW的窗体-urlencoded"
  3. "应用/ JSON"
  4. 但它正在接收" application / rss + xml"。你只需告诉RestKit会发生什么。

    如果它已经理解了mime类型,你可以问RestKit:

    [RKMIMETypeSerialization registeredMIMETypes];
    

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

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

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