ios - Restkit请求不发送参数

标签 ios iphone objective-c restkit restkit-0.20

我的实现不发送参数。这是请求描述符:

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 负载

最佳答案

确保您已设置:

manager.requestSerializationMIMEType = RKMIMETypeJSON;

默认为RKMIMETypeFormURLEncoded


根据您的评论和讨论,由于用户的类别错误,因此未使用映射。这是因为它是一个普通的 NSManagedObject 而不是 RKUser 实例。这意味着 RestKit 找不到合适的映射。造成此问题的原因是未在核心数据模型中的 User 实体上设置自定义类。

关于ios - Restkit请求不发送参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20509963/

相关文章:

iphone - NSInvocation需要NSMethodSignature

ios - #if 和 #ifdef Objective-C 预处理器宏有什么区别?

iphone - 为什么 UISearchBar 显示不正确?

iphone - 启动 iPhone 应用程序时的 EXC_BREAKPOINT

iphone - UIView 3DCube 像 Clear-app

ios - 有没有办法在不使用断点和步进 Xcode (iOS) 的情况下判断哪一行代码生成日志输出?

ios - 快速检查 3D Touch 是否可用

ios - 根据每个段中的标题更改分段控件的宽度?

ios - 如何在 map 上绘制路径线?

ios - UIImageView+AFNetworking.h 文件未找到