NSURLConnection and empty post variables
- by SooDesuNe
I'm at my wits end with this one, because I've used very similar code in the past, and it worked just fine.
The following code results in empty $_POST variables on the server. I verified this with:
file_put_contents('log_file_name', "log: ".$word, FILE_APPEND);
the only contents of log_file_name was "log: "
I then verified the PHP with a simple HTML form. It performed as expected.
The Objective-C:
NSString *word = "this_word_gets_lost";
NSString *myRequestString = [NSString stringWithFormat:@"word=%@",
word];
[self postAsynchronousPHPRequest:myRequestString toPage:@"http://www.mysite.com/mypage.php" delegate:nil];
}
-(void) postAsynchronousPHPRequest:(NSString*)request toPage:(NSString*)URL delegate:(id)delegate{
NSData *requestData = [ NSData dataWithBytes: [ request UTF8String ] length: [ request length ] ];
NSMutableURLRequest *URLrequest = [ [ NSMutableURLRequest alloc ] initWithURL: [ NSURL URLWithString: URL ] ];
[ URLrequest setHTTPMethod: @"POST" ];
[ URLrequest setHTTPBody: requestData ];
[ NSURLConnection connectionWithRequest:URLrequest delegate:delegate];
[URLrequest release];
}
The PHP:
$word = $_POST['word'];
file_put_contents('log_file_name', "log: ".$word, FILE_APPEND);
What am I doing wrong in the Objective-C that would cause the $_POST variable to be empty on the server?