Hee
У меня проблема с моим NSURLRequest HTTP POST, и я не могу выяснить, что происходит не так.
Это мой сервер php:
<html>
<head>
</head>
<body>
<?php
if (! isset($_POST['sometext'])) {
echo "NOT SET";
} else {
echo $_POST['sometext'];
}
?>
</body></html>
Это мой код цели c для публикации данных:
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);
Результат NSLog:
<html>
<head>
</head>
<body>
NOT SET
</body>
</html>
Спасибо уже