我正在尝试使用 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);
}];