2013-10-07 2 views
2

서버 DB에서 레코드를 삭제하는 데 사용되는 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

또는 내가 후 개체로 보내는 경우/패치 개체

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

답변

2

요청 매핑이 명시 적으로 DELETE 요청에 대해 수행되지 않습니다. RestKit은 삭제할 때 시스템을 사용하여 매개 변수를 URL에 추가 할 것으로 예상합니다. 삭제할 다른 방법을 계획해야합니다. 이것은 RestKit 매핑 작업을 사용하여 페이로드 데이터를 만든 다음이 메서드를 사용하여 URL 요청을 만들고 본문 데이터를 명시 적으로 설정할 수 있습니다.

+0

문서의 어딘가에서 이것을 발견 했습니까? – Hons

+0

@Hons 나는 코드를 보았다고 생각한다 ... – Wain

0

RESTKit은 request.body 매개 변수 으로 DELETE 요청을 기본적으로 지원하지 않습니다. HTTP 1.1은 request.body와 함께 DELETE 요청을 지원하지 않기 때문입니다. request.body를 명시 적으로 설정하는 작업이 있지만 은 해당 컴플렉스입니다.

요청이 곱슬 잘 작동하지만 HTTP와 함께, 어쩌면 컬 이 같은 DELETE request.body하지만 를 넣어 업그레이드와 DELETE 요청을 전송하지 않기 때문에, 우리는하지만 확실하지 않다.

+0

HTTP 1.1은 그것이 지원되지 않는다고 말하지 않는다. 다음은 추가 정보입니다. http://stackoverflow.com/questions/299628/is-anent-body-allowed-for-an-http-delete-request – ptoinson

관련 문제