Php 从服务器objective-c获取数据

Php 从服务器objective-c获取数据,php,objective-c,ios,http,nsurl,Php,Objective C,Ios,Http,Nsurl,我从服务器获取数据时遇到问题。服务器是我的本地主机 SMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"localhost"] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:10.0]; [request setHTTPMethod:@"GET"]; [request

我从服务器获取数据时遇到问题。服务器是我的本地主机

    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");
};
在localhost上,我有一个名为test.php的简单php脚本:

    <?php
echo "It works!!!"
?>


如果我在safari中打开localhost/test.php,我会看到“它可以工作!!!”

Try@http://localhost“而不是@“localhost”]

NSURLConnection connection==true responseData:(null)是的!!!谢谢现在我的响应数据是并正常保存到NSString*这是另一个问题,但NSString*结果=[[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding];