macool
macool

Reputation: 658

Restkit request not sending parameters

My implementation is not sending parameters. Here is the RequestDescriptor:

RKObjectMapping *userMapping = [RKObjectMapping requestMapping];
[userMapping addAttributeMappingsFromArray:@[@"nombres", @"telefono", @"direccion", @"email", @"identificacion", @"tipo_id", @"recibir_sms_ordenes", @"recibir_correos_ordenes"]];
RKRequestDescriptor *descriptor = [RKRequestDescriptor requestDescriptorWithMapping:userMapping objectClass:[RKUser class] rootKeyPath:@"me" method:RKRequestMethodAny];
[[RKObjectManager sharedManager] addRequestDescriptor:descriptor];

Here is the post request:

RKUser *user = [self currentUser].user;     // [self currentUser].user returns the current RKUser
RKObjectManager *manager = [RKObjectManager sharedManager];
[manager postObject:user path:@"/api/me.json" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
  NSLog(@"%@ %@", operation, mappingResult);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
  NSLog(@"%@ %@", error, operation);
}];

In the server, I only receive one empty current_user parameter. Any ideas on why?

PD. The server expects JSON payload under me key

Upvotes: 2

Views: 483

Answers (1)

Wain
Wain

Reputation: 119041

Ensure that you have set:

manager.requestSerializationMIMEType = RKMIMETypeJSON;

As the default is RKMIMETypeFormURLEncoded.


Based on your comments and discussion, the mapping isn't being used because the class of the user is wrong. This is because it is a plain NSManagedObject rather than an RKUser instance. This means RestKit can't find the appropriate mapping. The cause for this is the custom class not being set on the User entity in your Core Data model.

Upvotes: 3

Related Questions