2013-02-24 37 views
3

我正在用restkit 0.2敲打我的腦袋併發布對象。我試圖發佈一個對象與映射requestDescriptor但總是得到request.body =(null)在我的請求。我目前完全卡住了。Restkit 0.2 postObject總是返回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保持爲空。它不應該顯示我的對象爲JSON字符串嗎?映射工作正常,即

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

任何想法?

+1

最後我檢查(上週)的例子和大多數文件仍然是0.1或更早,因此現在是一個痛苦的世界。檢查[NSScreencast](https://www.nsscreencast.com)以獲取RestKit 0.2的視頻。 – zaph 2013-02-24 16:36:16

+0

同樣的問題在這裏....我正在努力挖.... – giuseppe 2013-12-17 17:10:01

回答

1
RKRequestDescriptor *reqDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:mapping objectClass:objectClass rootKeyPath:path]; 
[objectManager addRequestDescriptor:reqDescriptor]; 

對於映射使用[mapping inverseMapping]

對於objectClass的[Someclass class]。路徑可以大部分爲零。

1

我不知道,如果你設法解決這個問題,但我終於摸索出爲什麼我無法發佈 - 這是非常令人沮喪的:

我需要補充一點:

objectManager.requestSerializationMIMEType=RKMIMETypeJSON; 

獲取請求作爲JSON發佈。

從這一點上解決的問題。 不能解決爲什麼這不是一個更普遍的答案