3

私はrestkit0.2で頭を叩き、オブジェクトを投稿しています。マップされたrequestDescriptorを使用してオブジェクトを投稿しようとしていますが、リクエストで常にrequest.body =(null)を取得します。私は現在完全に立ち往生しています。

マッピングに次のコードを使用しています

// Construct a request mapping for our class
RKObjectMapping *requestMapping = [RKObjectMapping requestMapping];
[requestMapping addAttributeMappingsFromDictionary:@{
 @"command": @"requestedCommand" ,
 @"payload": @"payloadForCommand"
 }];
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:requestMapping objectClass:[ShoppingListAPI class] rootKeyPath:nil];
[manager addRequestDescriptor:requestDescriptor];

// create the object
ShoppingListAPI *shoppingListRequest = [[ShoppingListAPI alloc] init];
shoppingListRequest.payload = payload;
shoppingListRequest.command = @"getShoppingLists";

で投稿してみてください

[manager postObject:shoppingListRequest
                                path:@"shoppinglistWebservice.html"
                                parameters:nil
                                 success:^(RKObjectRequestOperation *operation, RKMappingResult *result) {
                                            DLog(@"We object mapped the response with the following result: %@", result);
                                    }
                                failure:^(RKObjectRequestOperation *operation, NSError *error) {
                                        DLog(@"Hit error: %@", error);

                                }];

ログから次のようになります

T restkit.network:RKHTTPRequestOperation.m:150 POST 'http://www.myhost.com/shoppinglistWebservice.html': 
request.headers={
Accept = "application/json";
"Accept-Language" = "de, en, fr, ja, nl, it, es, pt, pt-PT, da, fi, nb, sv, ko, zh-Hans, zh-Hant, ru, pl, tr, uk, ar, hr, cs, el, he, ro, sk, th, id, ms, en-GB, ca, hu, vi, en-us;q=0.8";
"Content-Type" = "text/html; charset=utf-8";
"User-Agent" = "myapp/1.0 (iPhone Simulator; iOS 6.0; Scale/2.00)";
}
request.body=(null)

RKObjectManager.hの実装例に従いましたが、成功しませんでした。request.bodyはnullのままです。オブジェクトをJSON文字列として表示することになっているのではないですか?マッピングは正常に機能しています。

Mapped attribute value from keyPath 'command' to 'requestedCommand'. Value: getShoppingLists

何か案は?

4

2 に答える 2

1

あなたがこれを解決できたかどうかはわかりませんが、投稿できなかった理由がようやくわかりました - とてもイライラしました:

これを追加する必要がありました:

objectManager.requestSerializationMIMEType=RKMIMETypeJSON; 

JSON として投稿するリクエストを取得します。

その時点から問題は解決しました。なぜこれがより一般的な答えではないのか理解できません

于 2014-08-23T11:25:21.807 に答える