我从服务器获取数据时遇到问题。服务器是我的本地主机。从服务器获取数据objective-c
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脚本调用的test.php:
<?php
echo "It works!!!"
?>
如果我在Safari中打开本地主机/ test.php的,我可以看到 “它的工作原理!!!”
什么问题? –
NSURLConnection连接== true responseData :(空) – Oleg