我难以从服务器获取数据。 服务器是我的当地东道主。
SMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"localhost"] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:10.0];
[request setHTTPMethod:@"GET"];
[request setHTTPBody:[NSString stringWithFormat:@"test.php"]];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if (connection)
{
NSLog(@"NSURLConnection connection==true");
NSURLResponse *response;
NSError *err;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
NSLog(@"responseData: %@", responseData);
}
else
{
NSLog(@"NSURLConnection connection==false");
};
关于当地东道方,我有简单的称为测试的网址。 php:
<?php
echo "It works!!!"
?>
If I m opening localhost/test.php in safari I can see "It works!!!"