删除对象在Restkit 0.20没有采取JSON值 [英] Delete Object in Restkit .20 did not take JSON Values
问题描述
我有一个用来删除服务器数据库记录的API。我用来构建与请求ID。它与卷曲工作的API,但在Restkit似乎给出一个错误。
该曲是:
卷曲-d'{前夜:{mod_policy:当前}}'-X DELETE -H内容类型:应用程序/ JSON https://myurl.com/eve/eve_id?token = my_aut_token \\&放大器; apikey = myapi_key
块引用>我是 POST和放大器检查; PATCH 。它采用
JSON
作为正确的形式。我RestKit code样品:</ P>
RKObjectMapping * requestMapping = [RKObjectMapping requestMapping][requestMapping addAttributeMappingsFromDictionary:@ {@modPolicy:@mod_policy}];RKRequestDescriptor * requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:requestMapping对象类:[事件类] rootKeyPath:@夏娃];RKObjectMapping * responseMapping = [RKObjectMapping mappingForClass:[事件类];[responseMapping addAttributeMappingsFromDictionary:@ {
@数据:@数据
@状态:@身份
}];RKResponseDescriptor * responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:responseMapping pathPattern:无的keyPath:@状态codeS:[indexSetWithIndex的NSIndexSet:200];[的ObjectManager addRequestDescriptor:requestDescriptor];
[的ObjectManager addResponseDescriptor:responseDescriptor];* NSString的urlPath = [的NSString stringWithFormat:@?/前夕/%@标记=%@&安培; apikey =%@,事件ID,loginToken,apiKey][的ObjectManager DeleteObject的:hubEve路径:urlPath参数:无成功:^(RKObjectRequestOperation *操作,RKMappingResult *结果)
{
DLOG(@响应code是%D,operation.HTT prequestOperation.response.status code);
活动* _event = [结果firstObject]
DLOG(@状态%@,_ event.status); 如果([_ eventt.status isEqualToString:@成功])
{
DLOG(移动下一步); }
}失败:^(RKObjectRequestOperation *操作,NSError *错误){
DLOG(错误%@,错误);
}];有些日志的详细信息,如果我发送DeleteObject的请求中:
request.body =(空)// Restkit登录
块引用>或者我叫为上传对象/片对象
request.body = {EVE:{mod_policy:所有的}} // Restkit登录
块引用>明确不适用于执行解决方案
请求映射删除请求。 RestKit预计,删除您要使用系统参数加入到URL时。你需要计划在要删除一些其他的方法。这可能是使用RestKit映射操作,以创建净荷数据,然后使用方法来创建URL请求和显式设置体数据
I have an API which is used to delete a record in server DB. I used to construct the API with the request ID .It was working with CURL, but in Restkit it seems to give an error. The Curl is:
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.
I checked with POST & PATCH. It takes the
JSON
as a correct form.My RestKit Code Sample:
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); }];
Some log details, if I send As DeleteObject in request:
request.body=(null) //Restkit Log
Or if I send as post Object/Patch Object
request.body={"eve":{"mod_policy":"all"}} //Restkit Log
解决方案Request mapping is explicitly not performed for
DELETE
requests. RestKit expects that when deleting you will be using the system to add parameters into the URL. You will need to plan some other method by which to delete. This could be using the RestKit mapping operation to create the payload data and then using the methods to create the URL request and setting the body data explicitly.这篇关于删除对象在Restkit 0.20没有采取JSON值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!