0

我正在为我的项目使用 Restkit 0.20。我提出这样的要求。

NSData *postData  = [params dataUsingEncoding:NSUTF8StringEncoding];
    NSURL *url = [NSURL URLWithString:baseUrl];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:path relativeToURL:url]];
    [request setHTTPMethod:@"POST"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody:postData];
    RKObjectManager *manager = [[RestKit sharedDataManager] objectManager];
    RKManagedObjectRequestOperation *operation = [manager managedObjectRequestOperationWithRequest:request managedObjectContext:manager.managedObjectStore.persistentStoreManagedObjectContext success:^(RKObjectRequestOperation *operation1, RKMappingResult *mappingResult) {
             block ([mappingResult array]);

        } failure:^(RKObjectRequestOperation *operation1, NSError *error) {
            RKLogDebug(@"Failure %@",error.debugDescription);
            block (error);
        }];

在竞争映射操作之后,我使用块返回一个数组。我需要在委托中获得响应以用于某些操作。是否有任何类似于 Restkit0.10 中的 didReceiveResponse 的方法,而且我知道这个线程https://groups.google.com/forum/#!topic/restkit/TrWH5GR-gFU布莱克提到我们可以完全控制通过 NSURLRequest 对象的标头。但是当我使用 RKManagedObjectRequestOperation 时如何使用 NSURLRequest。任何人都可以发布一些例子。

谢谢

4

2 回答 2

1

如果你只需要 response.statuscode 你可以得到它。在 restkit 成功块中,我们有两个参数(RKObjectRequestOperation *operation, RKMappingResult *result)

要获得响应,您可以使用它。

operation.HTTPRequestOperation.response.statusCode
于 2014-10-14T15:22:33.097 回答
0

You already have a request : NSMutableURLRequest (which is the mutable subclass of NSURLRequest), so any required headers can be set there.

When the success callback is called it includes the RKObjectRequestOperation, you can request the HTTPRequestOperation (an instance of RKHTTPRequestOperation), from which you can request response (an instance of NSHTTPURLResponse).


Based on your updated description you would need to subclass RKManagedObjectRequestOperation and override performMappingOnResponse: in order to insert your additional processing before calling super.

于 2013-09-20T09:22:45.690 回答