I've got an iPhone app sending data to my server with a post request:
-(void) sendDataToServer:(NSString*)myString {
NSURL *url = [NSURL URLWithString:@"http://site.com/script.php"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request addRequestHeader:@"Name" value:myString];
[request startAsynchronous];
}
But when I try
$blah = $_POST['Name'];
$fp = fopen('test.txt', 'w');
fwrite($fp, $blah);
fclose($fp);
A blank line gets written, meaning the variable doesn't exist. If i set it to write any old string it works, meaning them request is getting through, just not the data it carries.
The myString
variable does have a value too, I checked in the debugger, so I'm not sending an empty string.
You are setting a Header, but want you want is
[request appendPostData:[@"This is my data" dataUsingEncoding:NSUTF8StringEncoding]];
or:
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request addPostValue:@"Ben" forKey:@"name"];