0

我正在尝试使用 RestKit 发送 DELETE 请求,但它似乎总是作为“GET”发送。这是我的代码:

RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor
                                       responseDescriptorWithMapping:[self objectMapping]
                                       method:RKRequestMethodDELETE
                                       pathPattern:nil
                                       keyPath:nil
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];


RKObjectRequestOperation *objectRequestOperation = [[RKObjectRequestOperation alloc] initWithRequest:request responseDescriptors:@[ responseDescriptor ]];
[objectRequestOperation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {

    [delegate onRequestSuccess:mappingResult.array];

} failure:^(RKObjectRequestOperation *operation, NSError *error) {
    RKLogError(@"operation failed with error: %@", error);
    [delegate onRequestError:operation message:error];
}];

[objectRequestOperation start];

我还尝试使用 RKObjectManager:deleteObject,它确实正确发送了 DELETE 请求,但响应没有被映射。

RKObjectManager *manager = [RKObjectManager managerWithBaseURL:request.url];
[manager addResponseDescriptor:responseDescriptor];
[manager deleteObject:nil path:request.urlString parameters:nil
              success:^(RKObjectRequestOperation *operation , RKMappingResult *mappingResult) {
                  Tag *tag = mappingResult.firstObject; // this is null, does not get mapped

              } failure:^(RKObjectRequestOperation *operation , NSError *error) {
                  RKLogError(@"Error deleting tag %@, error: %@", tagId, error);
              }];
4

1 回答 1

1

如果您正在使用RKObjectRequestOperation,则需要request自己配置。它是 GET,因为这是默认设置。

如果你使用RKObjectManager,那么你可以使用deleteObject它将为你做的。

于 2013-07-29T19:13:11.663 回答