iOS:带参数的RESTKit RKRequestMethodDELETE

时间:2014-09-30 05:01:48

标签: ios restkit restkit-0.20 http-delete

如何使用RKRequestMethodDELETE请求发送参数。我需要发送groupId(INT)和users(数组)。

以下是我正在使用的代码,并将其附加到网址:

https://www.domain.com/g/members?groupId=15&users[][userId]=john.doe

相反,我想将请求发送到:

https://www.domain.com/g/members

并将groudIdusers数组作为参数的一部分作为请求的一部分。

我需要发送

{
    [self newObjectManager];
    [self refreshMOC];

    RKEntityMapping *groupMapping = [RKEntityMapping mappingForEntityForName:kEntityGroup inManagedObjectStore:self.objectManager.managedObjectStore];
    groupMapping = [TBSRESTMappingProvider groupGetMapping:groupMapping];

    NSIndexSet *statusCodeSet = RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful);
    RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:groupMapping
                                                                                            method:RKRequestMethodDELETE
                                                                                       pathPattern:kPathPOSTGroupMembers
                                                                                           keyPath:nil
                                                                                       statusCodes:statusCodeSet];

    NSArray *stringMembers = [self NSStringMembersFromFriendObjects:members];

    NSMutableURLRequest *request = [self.objectManager.HTTPClient requestWithMethod:kRequestMethodDELETE
                                                                               path:kPathPOSTGroupMembers
                                                                         parameters:@{ @"groupId": group.groupId,
                                                                                       @"users" : stringMembers }];

    [self.objectManager.HTTPClient registerHTTPOperationClass:[AFHTTPRequestOperation class]];

    RKManagedObjectRequestOperation *operation = [[RKManagedObjectRequestOperation alloc] initWithRequest:request responseDescriptors:@[responseDescriptor]];
    operation.managedObjectContext = self.objectManager.managedObjectStore.mainQueueManagedObjectContext;
    operation.managedObjectCache = self.objectManager.managedObjectStore.managedObjectCache;

    [operation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {

    } failure:^(RKObjectRequestOperation *operation, NSError *error) {

    [operation start];
}

0 个答案:

没有答案