Restkit请求不发送参数 [英] Restkit request not sending parameters
问题描述
我的实现不是发送参数。这是RequestDescriptor:
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];
这是邮寄申请:
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
参数。关于为什么的任何想法?
In the server, I only receive one empty current_user
parameter. Any ideas on why?
PD。服务器期望我
键
推荐答案
确保你有set:
manager.requestSerializationMIMEType = RKMIMETypeJSON;
默认为 RKMIMETypeFormURLEncoded
。
根据您的评论和讨论,由于用户的类错误,因此未使用映射。这是因为它是一个简单的 NSManagedObject
而不是 RKUser
实例。这意味着RestKit找不到合适的映射。原因是您的核心数据模型中的用户
实体未设置自定义类。
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.
这篇关于Restkit请求不发送参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!