1

Restkit GET 操作を行っていますが、Restkit でエラーが発生します。Chrome の REST コンソールで同じ操作を試みたところ、次のように動作しました。

GET 操作の詳細は次のとおりです。 URL: 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

なにか提案を?

4

1 に答える 1

1

エラーはすでにヒントを示しています。デフォルトでは、「text/xml」をコンテンツ タイプとして受け入れません。今のところ、それは受け入れます

  • application/x-www-form-urlencoded
  • アプリケーション/json

使用して登録しRKMIMETypeSerialization、受け入れられたコンテンツ タイプの 1 つに「text/xml」を追加できます。

[RKMIMETypeSerialization registerClass:[RKXMLReaderSerialization class] forMIMEType:RKMIMETypeTextXML];
[objectManager setAcceptHeaderWithMIMEType:@"text/xml"];
于 2013-10-25T07:20:36.033 に答える