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 success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult){ if (success) { NSArray *userArray = [mappingResult array]; success([userArray firstObject]); } } failure:^(RKObjectRequestOperation *operation, NSError *error){ NSLog(@"Error: %@", error); if (failure) { failure(operation, error); } }]; } |
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.identificationAttributes = @[ @"uuid" ]; [userMapping addAttributeMappingsFromDictionary:@{@"email": @"email", @"first_name": @"firstName", @"last_name": @"lastName", @"is_logged_in": @"isLoggedIn", @"site_id": @"siteID", @"user_name": @"username", @"uuid": @"uuid"}]; return userMapping; } |
和 UserObject(在 .m 中每个都设置为 @dynamic):
1 2 3 4 5 6 7 8 9 10 11 | @interface UserObject : NSManagedObject @property (strong, nonatomic) NSString *email; @property (strong, nonatomic) NSString *firstName; @property (strong, nonatomic) NSString *lastName; @property (assign, nonatomic) BOOL isLoggedIn; @property (strong, nonatomic) NSNumber *siteID; @property (strong, nonatomic) NSString *username; @property (strong, nonatomic) NSString *uuid; @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。
终于弄清楚了,当然这是一个非常愚蠢的问题。服务器需要一个参数字典,但我的对象管理器的
的字典