我正在使用Restkit 0.10.0,我无法弄清楚如何使用对象映射来执行http帖子。这就是我到目前为止所做的:
baseUrl = [[NSURL alloc] initWithString:@"http://www.whatever.com"];
RKObjectManager* objectManager = [RKObjectManager managerWithBaseURL:baseUrl];
objectManager.acceptMIMEType = RKMIMETypeJSON;
objectManager.serializationMIMEType = RKMIMETypeJSON;
// mapping
RKObjectMapping * userMapping = [RKObjectMapping mappingForClass:[User class]];
[userMapping mapKeyPath:@"id" toAttribute:@"id"];
[userMapping mapKeyPath:@"g" toAttribute:@"genre"];
[[objectManager mappingProvider] addObjectMapping: userMapping];
[[RKObjectManager sharedManager].mappingProvider setMapping:userMapping forKeyPath:@"response"];
// post request
NSArray *objects = [NSArray arrayWithObjects:@"Montreal", @"Canada", @"", @"", @"", @"1", @"0", @"2", @"0", nil];
NSArray *keys = [NSArray arrayWithObjects:@"c", @"co", @"lat", @"lng", @"rad", @"s", @"o", @"ageG", @"w_ageG", nil];
NSDictionary *queryParameters = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
NSString *getResourcePath = RKPathAppendQueryParams(@"people.php", queryParameters);
// send request and wait for answer, delegate self will map objects
[[RKObjectManager sharedManager] loadObjectsAtResourcePath:@"/people.php" delegate:self];
当我这样做时,用
$city = $_POST['c'];
例如,在php文件中,没有任何反应。有任何想法吗?谢谢!
答案 0 :(得分:3)
RKURL *rkUrl = [RKURL URLWithBaseURL:baseUrl resourcePath:postString];
RKObjectLoader* loader = [[RKObjectLoader alloc] initWithURL:rkUrl mappingProvider:[RKObjectManager sharedManager].mappingProvider];
loader.method = RKRequestMethodPOST;
loader.delegate = self;
loader.objectMapping = [[RKObjectManager sharedManager].mappingProvider objectMappingForClass:[MyObject class]];
[loader send];