NSURLConnection and empty post variables
Posted
by SooDesuNe
on Stack Overflow
See other posts from Stack Overflow
or by SooDesuNe
Published on 2010-04-20T23:06:36Z
Indexed on
2010/04/20
23:13 UTC
Read the original article
Hit count: 317
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?
© Stack Overflow or respective owner