Hee,
I got a problem with my NSURLRequest HTTP POST and i cannot find out what is going wrong.
This is my server side php:
<html>
<head>
</head>
<body>
<?php
if (! isset($_POST['sometext'])) {
echo "NOT SET";
} else {
echo $_POST['sometext'];
}
?>
</body></html>
This is my Objective c code to post the data:
NSString *urlString = @"http://localhost:8888/postpage";
NSURL *url = [[NSURL alloc] initWithString:urlString];
NSMutableURLRequest *urlRequest=[NSMutableURLRequest requestWithURL:url];
[url release];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[urlRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
NSString *postString = @"sometext=Hello&language=en";
NSString *msgLength = [NSString stringWithFormat:@"%d", [postString length]];
[urlRequest setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
NSString *returnString = [[NSString alloc] initWithData:[NSURLConnection sendSynchronousRequest:urlRequest returningResponse:nil error:nil] encoding:NSUTF8StringEncoding];
NSLog(@"%@",returnString);
The result of the NSLog is:
<html>
<head>
</head>
<body>
NOT SET
</body>
</html>
Thanks already