在 Restkit .20 中删除对象没有采用 JSON 值 [英] Delete Object in Restkit .20 did not take JSON Values

查看:33
本文介绍了在 Restkit .20 中删除对象没有采用 JSON 值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 API,用于删除服务器数据库中的记录.我曾经使用请求 ID 构建 API.它正在使用 CURL,但在 Restkit 中它似乎给出了错误.卷曲是:

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.

我检查了 POST &补丁.它采用 JSON 作为正确的形式.

I checked with POST & PATCH. It takes the JSON as a correct form.

我的 RestKit 代码示例:

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);
 }];

一些日志详细信息,如果我在请求中发送 As DeleteObject:

Some log details, if I send As DeleteObject in request:

request.body=(null)//Restkit 日志

或者如果我作为发布对象/补丁对象

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

推荐答案

对于 DELETE 请求,不明确执行请求映射.RestKit 期望在删除时您将使用系统将参数添加到 URL 中.您将需要计划一些其他删除方法.这可能是使用 RestKit 映射操作创建有效负载数据,然后使用方法创建 URL 请求并显式设置正文数据.

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 .20 中删除对象没有采用 JSON 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆