简体   繁体   中英

get data from server objective-c

I have a problem getting data from the server. server is my localhost.

    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");
};

on localhost I have simple php script called test.php:

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

If I'm opening localhost/test.php in safari I can see "It works!!!"

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM