2013-10-07 31 views
2

我有一個API用於刪除服務器數據庫中的記錄。我曾經使用請求ID構建API。它使用CURL,但在Restkit中它似乎給出了一個錯誤。 的捲曲是:Restkit .20中的刪除對象沒有使用JSON值

curl -d '{eve:{mod_policy:"current"}}' -X DELETE -H Content-Type:application/json https://myurl.com/eve/eve_id?token=my_aut_token\&apikey=myapi_key.

POST & PATCH檢查。它需要JSON作爲一個正確的形式。

我RestKit代碼示例:

RKObjectMapping *requestMapping = [RKObjectMapping requestMapping]; 

[requestMapping addAttributeMappingsFromDictionary:@{ @"modPolicy" : @"mod_policy"}]; 

RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:requestMapping objectClass:[Event class] rootKeyPath:@"eve"]; 

RKObjectMapping *responseMapping = [RKObjectMapping mappingForClass:[Events class]]; 

[responseMapping addAttributeMappingsFromDictionary:@{ 
                 @"data" : @"data", 
                 @"status":@"status" 
                 }]; 

RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:responseMapping pathPattern:nil keyPath:@"" statusCodes:[NSIndexSet indexSetWithIndex:200]]; 

[objectManager addRequestDescriptor:requestDescriptor]; 
[objectManager addResponseDescriptor:responseDescriptor]; 

NSString * urlPath = [NSString stringWithFormat:@"/eve/%@?token=%@&apikey=%@",eventID,loginToken,apiKey]; 

[objectManager deleteObject:hubEve path:urlPath parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *result) 
{ 
    DLog(@" response code is %d",operation.HTTPRequestOperation.response.statusCode); 
    Events * _event = [result firstObject]; 
    DLog(@"status %@",_event.status); 

    if([_eventt.status isEqualToString:@"success"]) 
    { 
     DLog("Move Next"); 

    } 
} failure:^(RKObjectRequestOperation *operation, NSError *error) { 
    DLog("error %@",error); 
}]; 

一些日誌的詳細信息,如果我發送DeleteObject的請求中:

request.body=(null) //Restkit Log

或者我叫爲Post對象/補丁對象

明確不 DELETE請求進行

request.body={"eve":{"mod_policy":"all"}} //Restkit Log

回答

2

請求映射。 RestKit預計,在刪除時,您將使用系統將參數添加到URL中。您需要規劃一些其他要刪除的方法。這可以使用RestKit映射操作來創建有效負載數據,然後使用這些方法創建URL請求並明確設置主體數據。

+0

你是否在文檔的某個地方找到了這個地方? – Hons

+0

@Hons我想我看了看代碼... – Wain

0

原因是RESTKit不支持使用request.body參數 的DELETE請求,因爲HTTP 1.1不支持使用request.body的 DELETE請求。有一個工作可以明確設置request.body,但它的複雜。

請求工作很好地捲曲而與HTTP,也許是因爲捲曲 不發送刪除與request.body爲DELETE,但其升級 放的要求,我們不能肯定,但。

+0

HTTP 1.1並沒有說它不被支持。這裏是一些更多的信息:http://stackoverflow.com/questions/299628/is-an-entity-body-allowed-for-an-http-delete-request – ptoinson