0

I'm using Restkit 0.10.0 and I can't figure out how to do a http post with object mapping. This is what I have so far:

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]; 

When I do this post, with

$city = $_POST['c'];

in the php file for example, nothing happens. Any ideas? Thanks!

4

1 回答 1

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];
于 2012-06-12T10:33:14.107 回答