Restkit request not sending parameters

本秂侑毒 提交于 2019-12-17 20:41:05

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/20509963/restkit-request-not-sending-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!