2013-10-07 26 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