简体   繁体   中英

How to use loadObjectsAtResourcePath from Restkit 0.10.0 for a http post to a php script?

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM