我有一个 API 用于删除服务器数据库中的记录。我曾经使用请求 ID 构建 API。它正在使用 CURL,但在 Restkit 中它似乎给出了错误。卷曲是:
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);
}];
一些日志详细信息,如果我在请求中发送 As DeleteObject:
request.body=(null) //Restkit Log
或者,如果我作为帖子对象/补丁对象发送
request.body={"eve":{"mod_policy":"all"}} //Restkit Log