Can’t get RestKit 0.2 to POST parameters
所以我正在尝试使用
当我注销
(以前我只是使用 and
任何帮助将不胜感激。
编辑更多代码:
我有一个名为 UserAuthService 的 RKObjectManager 子类,使用 RKMIMETYPEJSON 作为 requestSerializationMIMEType,具有以下请求描述符设置:
1
2 3 4 5 6 7 |
// User
RKResponseDescriptor *userResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:[UserAuthMappingProvider userMapping] method:RKRequestMethodPOST pathPattern:@"user/login" keyPath:@"response.users" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]; [self addResponseDescriptor:userResponseDescriptor]; |
我实际请求的方法是:
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
– (void)logUserInWithEmail:(NSString *)email andPassword:(NSString *)password success:(void (^)(UserObject *))success failure:(void (^)(RKObjectRequestOperation *, NSError *))failure { // Request Params NSDictionary *params = @{@"email": email, @"password": password}; NSLog(@"Params: %@", params); [self postObject:nil path:@"user/login" parameters:params } if (failure) |
UserAuthMappingProvider 中的 userMapping 方法如下所示:
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
+ (RKEntityMapping *)userMapping { AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; RKEntityMapping *userMapping = [RKEntityMapping mappingForEntityForName:@"User" inManagedObjectStore:appDelegate.managedObjectStore]; [userMapping addAttributeMappingsFromDictionary:@{@"email": @"email", |
和 UserObject(在 .m 中每个都设置为 @dynamic):
1
2 3 4 5 6 7 8 9 10 11 |
@interface UserObject : NSManagedObject
@property (strong, nonatomic) NSString *email; @end |
我返回的错误是:
1
|
Error Domain=org.restkit.RestKit.ErrorDomain Code=-1011"Expected status code in (200-299), got 400" UserInfo=0x8eadbf0 {NSLocalizedRecoverySuggestion={"required_parameters":{"email":"string","password":"string"},"status":"failed","message":"Insufficient information passed. see ‘required_parameters’"}
|
基本上我的目标是获取用户/登录调用的成功响应并将其映射到 UserObject。
终于弄清楚了,当然这是一个非常愚蠢的问题。服务器需要一个参数字典,但我的对象管理器的
的字典
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/268598.html