Restkit请求不发送参数

时间:2013-12-11 03:28:20

标签: ios iphone objective-c restkit restkit-0.20

我的实现不是发送参数。这是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];

这是帖子请求:

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);
}];

在服务器中,我只收到一个空的current_user参数。关于为什么的任何想法?

PD。服务器期望me密钥

下的JSON有效负载

1 个答案:

答案 0 :(得分:3)

确保您已设置:

manager.requestSerializationMIMEType = RKMIMETypeJSON;

默认为RKMIMETypeFormURLEncoded


根据您的评论和讨论,未使用映射,因为用户的类是错误的。这是因为它是普通的NSManagedObject而不是RKUser实例。这意味着RestKit找不到合适的映射。原因是未在Core Data模型中的User实体上设置自定义类。