I am using RestKit and I am trying to publish an object with a request parameter (auth token in the form token=<token> ), but I cannot figure out how to make it work. That's what I'm doing...
First, I add the mapping of the request object to the manager:
RKObjectMapping *requestMapping = [RKObjectMapping requestMapping]; [requestMapping addAttributeMappingsFromDictionary:@{ @"id" : @"id", @"name" : @"name", @"latitude" : @"latitude", @"longitude" : @"longitude" }]; RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:requestMapping objectClass:[Location class] rootKeyPath:nil]; [manager addRequestDescriptor:requestDescriptor];
Then I make a request:
RKManagedObjectRequestOperation *operation = [RKObjectManager.sharedManager appropriateObjectRequestOperationWithObject:self method:RKRequestMethodPOST path:@"/api/v1/users/3/locations" parameters:@{@"token" : token}]; [operation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) { Location * location = (Location*)mappingResult; self.id = Location.id; } failure:^(RKObjectRequestOperation *operation, NSError *error) { ALog(@"fail!"); }]; [RKObjectManager.sharedManager enqueueObjectRequestOperation:operation];
When a request is made, the Location object is serialized in JSON and completely placed in the request body. However, instead of the token being added to the query string, it is added as JSON to the request body.
Example:
request.body={"id":0,name="test","longitude":-0.1337,"latitude":51.50998,"token":"Z3JlZ2c6MTM2MDU2OTk2MDY2OTpMajkxd01acWxjcGg1dEpFVy9IaEcwNTcyMWJkSEpnTFRTQTI2eXNlN29VOVRTc1UwV1lEU0E9PQ=="}
Any help is much appreciated!
source share