If I have a php file on my site, how could I pass an NSString
to a POST
variable (with objective-c) so I can echo it onto the page? I am new to php, so sorry if this is obvious.
Using ASIFormDataRequest
:
NSURL *myURl = [[NSURL alloc] initWithString:@"http://www.mysite/something.php"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:myURl];
[request setDelegate:self];
[request setUsername:@"username"];
[request setPassword:@"password"];
[request setPostValue:@"This is a string" forKey:@"phpVar"];
[request startAsynchronous];
Delegate method calls:
-(void)requestFailed:(ASIHTTPRequest *)request
{
NSError *error = [request error];
NSLog(@"Failed %@ with code %d and with userInfo %@",[error domain],[error code],[error userInfo]);
}
-(void)requestFinished:(ASIHTTPRequest *)request
{
NSLog(@"Finished : %@",[request responseString]);
}
There are a couple of problems here:
- Even if I enter the incorrect credentials,
requestFinished
only gets called.
Edit -- Just fixed (1), created a password protected directory and stuck the php file in there.
- "This is a string" isn't getting passed to phpVar in the php file and won't display on the page
Here is what I wrote in php:
<?php
$blah = $_POST['phpVar'];
echo $blah;
?>
Thanks for your help.