2013-10-25 131 views
1

我正在执行Restkit GET操作,但在Restkit中出现错误。我想同样的操作与REST控制台上的Chrome和它的工作原理:获取操作时出现REstkit错误

GET操作的细节是: 网址:https://www.ez-point.com/ezpoints 操作:GET 认证头:xxxxxxxxxxxxxxxxxxx

随着Chrome的REST控制台,它工作和我在JSON得到适当的回应。

使用Restkit,它不起作用。这些都是我Restkit代码:

//trying restkit 
    NSURL *endpoint = [NSURL URLWithString:@"https://www.ez-point.com/"]; 
    RKObjectManager* objectManager = [RKObjectManager managerWithBaseURL:endpoint]; 
    [objectManager.HTTPClient setAuthorizationHeaderWithToken:@"xxxxxxxxxxxxxxxxxxx"]; 
    [objectManager getObjectsAtPath:@"ezpoints" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) { 
     NSLog(@"Success"); 
     //NSLog(mappingResult); 
    } failure:^(RKObjectRequestOperation *operation, NSError *error) { 
     NSLog(@"Failure"); 
     //NSLog(operation); 
     //NSLog(error); 
    }]; 

我得到这个错误:

2013-10-25 11:00:11.690 EZ-POINT[1089:c07] I restkit:RKLog.m:34 RestKit logging initialized... 
2013-10-25 11:00:12.820 EZ-POINT[1089:c07] I restkit.network:RKObjectRequestOperation.m:180 GET 'https://www.ez-point.com/ezpoints' 
2013-10-25 11:00:14.184 EZ-POINT[1089:4507] E restkit.network:RKObjectRequestOperation.m:576 Object request failed: Underlying HTTP request operation failed with error: Error Domain=org.restkit.RestKit.ErrorDomain Code=-1016 "Expected content type {(
    "application/x-www-form-urlencoded", 
    "application/json" 
)}, got text/html" UserInfo=0x110a3560 {AFNetworkingOperationFailingURLRequestErrorKey=<NSMutableURLRequest https://www.ez-point.com/ezpoints>, NSErrorFailingURLKey=https://www.ez-point.com/ezpoints, NSLocalizedDescription=Expected content type {(
    "application/x-www-form-urlencoded", 
    "application/json" 
)}, got text/html, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x110b42b0>} 
2013-10-25 11:00:14.185 EZ-POINT[1089:4507] E restkit.network:RKObjectRequestOperation.m:243 GET 'https://www.ez-point.com/ezpoints' (401 Unauthorized/0 objects) [request=0.0000s mapping=0.0000s total=1.3657s]: Error Domain=org.restkit.RestKit.ErrorDomain Code=-1016 "Expected content type {(
    "application/x-www-form-urlencoded", 
    "application/json" 
)}, got text/html" UserInfo=0x110a3560 {AFNetworkingOperationFailingURLRequestErrorKey=<NSMutableURLRequest https://www.ez-point.com/ezpoints>, NSErrorFailingURLKey=https://www.ez-point.com/ezpoints, NSLocalizedDescription=Expected content type {(
    "application/x-www-form-urlencoded", 
    "application/json" 
)}, got text/html, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x110b42b0>} 
2013-10-25 11:00:14.599 EZ-POINT[1089:c07] Failure 

什么建议吗?

回答

1

该错误已经提供了一个提示:默认情况下,它不接受“text/xml”作为内容类型。眼下,它接受

  • 应用程序/ x-WWW窗体-urlencoded
  • 应用/ JSON

可以使用RKMIMETypeSerialization注册,并为 “text/xml的” 添加到接受的一个内容类型:

[RKMIMETypeSerialization registerClass:[RKXMLReaderSerialization class] forMIMEType:RKMIMETypeTextXML]; 
[objectManager setAcceptHeaderWithMIMEType:@"text/xml"]; 
+0

我在u're app中添加了代码行,但同样的错误。 – Noor

+0

是的,因为你没有注册序列化类(见编辑答案)。 – tilo

+0

随着你的代码,我收到一个错误:未知的接收者'RKXMLReaderSerialization';你的意思是RKURLEncodedSerialization? – Noor