我有一个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
你是否在文档的某个地方找到了这个地方? – Hons
@Hons我想我看了看代码... – Wain