Reputation: 381
I've got an NSMutable Dictionary that has restaurant item names and their quantities. I'm trying to send this dictionary to a PHP web page that will be able to properly read it. I'm also sending additional parameters (separate from the dictionary) such as delivery details, username, etc as well.
Keep in mind that the PHP web page will not know which keys the dictionary has since it will be different depending on the restaurant. That's why I need to send the dictionary itself over and then have the PHP "decode" it so to speak.
Is there anyway to us NSURLSession
or even AFHTTPNetowrking
to accomplish this?
Upvotes: 2
Views: 53
Reputation: 2868
Objective-c
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSDictionary *parameters = @{@"foo": @"bar"};
[manager POST:@"http://example.com/resources.json" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
// if you want to read any json simply do.
[responseObject objectForKey:@"my_json_key"];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
PHP
echo $_POST['foo'];
Remember to import the library to your project https://github.com/AFNetworking/AFNetworking
Upvotes: 2