如何使用RestKit来调用Web服务

时间:2014-03-03 05:57:08

标签: ios restkit

我正在为ios开发一个应用程序。在那我需要使用RestKit框架,所以我使用CocoaPods集成它,但在调用webservice时无法得到如何做。示例我有一个像http://dev.api.sample.com/services/v1/这样的webservice url,添加用户的路径是users / add,我需要以json格式发送参数,我将获得一些json格式的数据,请求方法是PUT。如果有人知道锄头使用请告诉我。 我试着用这种方式:

 NSURL *baseURL = [NSURL URLWithString:@"http://dev.api.sample.com/services/v1/"];
    AFHTTPClient *client1 = [[AFHTTPClient alloc] initWithBaseURL:baseURL];
    objectManager = [RKObjectManager sharedManager];
    [objectManager setRequestSerializationMIMEType:RKMIMETypeJSON];
    [objectManager setHTTPClient:client1];
    [objectManager setAcceptHeaderWithMIMEType:@"application/json"];
RKObjectRequestOperation *operation = [objectManager appropriateObjectRequestOperationWithObject:self method:RKRequestMethodPUT path:@"users/add" parameters:data];

    [operation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *result) {
        NSLog(@"success");
        // success is called, but the result does not contain what the response JSON is
    } failure:^(RKObjectRequestOperation *operation, NSError *error) {
        // failure
        NSLog(@"fail");
    }];

    [operation start];

但我无法对上述例子做出任何回应。

0 个答案:

没有答案