I'm having some problems with sending POST data to a PHP script with NSURLConnection. This is my code:
const char *bytes = [[NSString stringWithFormat:@"<?xml version=\"1.0\"?>\n<mydata>%@</mydata>", data] UTF8String];
NSURL *url = [NSURL URLWithString:@"http://myurl.com/script.php"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[NSData dataWithBytes:bytes length:strlen(bytes)]];
NSURLResponse *response;
NSError *err;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
NSLog(@"responseData: %@", responseData);
And my script.php is as simple as this:
<?php
echo $_POST['mydata'];
?>
This have worked for me in the past, but for some reason the output I get from NSLog(@"responseData: %@", responseData);
now is just "<>" instead of "theData".
Probably some lame mistake somewhere but I can't seem to find it? Any ideas?