In RestKit Version 0.10.x I used
[[RKObjectManager sharedManager] loadObjectsAtResourcePath:@"/special/path" usingBlock:^(RKObjectLoader *loader) {
loader.objectMapping = aMapping;
loader.delegate = _delegate;
loader.method = RKRequestMethodPOST;
loader.userData = [MobileGatewayReauthentication class];
loader.params = [anDictionary toJsonRKParam];
}];
to add a NSDictionary to loader.params to send a collection of parameters as the HTTP body of the request.
Since RestKit 0.20.0 the method loadObjectsAtResourcePath has been replaced by the following method, where it is no longer possible to pass a NSDictionary in parameters, which is used as HTTP Body (JSON encoded):
[RKObjectManager.sharedManager getObjectsAtPath:path parameters:params success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult)
{
NSLog(@"success");
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"failure");
}];
When working with [[RKObjectManager sharedManager].HTTPClient (AFNetworking) it works like a charm when setting:
[[RKObjectManager sharedManager].HTTPClient setParameterEncoding:AFJSONParameterEncoding];
[[RKObjectManager sharedManager].HTTPClient postPath:path parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Response: %@", operation.responseString);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@",error.localizedDescription);
}];
But I need the higher-level object mapper.
[[RKObjectManager sharedManager].HTTPClient setParameterEncoding:AFJSONParameterEncoding];
has no effect on [RKObjectManager sharedManager] but
[[RKObjectManager sharedManager].HTTPClient setDefaultHeader:@"aHeader" value:@"aValue"];
has. So I assumed that setParameterEncoding works, too.
Is it a bug, is it not yet implemented, or have I missed something?
Thanks a lot.
I really have missed something.
loadObjectsAtResourcePathget’s (for sure) called withRKRequestMethodGET. So the parameters get append to the URL, not to the HTTP body.To append the parametrs as a JSON HTTP body, you have to use a post method, for example
Excuse the hasty question. I should have seen it before.