我的实现不是发送参数。这是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
密钥
答案 0 :(得分:3)
确保您已设置:
manager.requestSerializationMIMEType = RKMIMETypeJSON;
默认为RKMIMETypeFormURLEncoded
。
根据您的评论和讨论,未使用映射,因为用户的类是错误的。这是因为它是普通的NSManagedObject
而不是RKUser
实例。这意味着RestKit找不到合适的映射。原因是未在Core Data模型中的User
实体上设置自定义类。