I have tried sending POST data to a php file with asynch and synch NSURLConnection and ASIHTTPRequest but both refuse to actually echo anything in $_POST. My s.php file looks like so:
<?php
echo 'Hi There';
echo $_POST['fname'];
foreach ($_POST as $i => $value) {
echo($i);
}
?>
My ASIHTTRequest is:
NSURL *url = [[NSURL alloc] initWithString:@"http://server.com/s.php"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:@"Ben" forKey:@"fname"];
[request setDelegate:self];
[request setDidFinishSelector:@selector(requestFinished:)];
[request startAsynchronous];
Which only prints the Hi There line when it comes back to requestFinished.
Edit: By using ASIFormDataRequest, I am pretty sure request is set to POST already, at least there doesn't seem to be a way to set it manually. When I tried NSURLConnection I used:
NSURL *url = [NSURL URLWithString:@"http://server.com/s.php"];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:[[NSString stringWithFormat:@"fname=carl"] dataUsingEncoding:NSUTF8StringEncoding]];
NSURLResponse *response;
NSData *urlData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];
NSString *stringResponse = [[NSString alloc] initWithData:urlData encoding:NSASCIIStringEncoding];
NSLog(@"%@",stringResponse);
And still only getting the Hi There line, and also getting normal replies when I use an html form.