NSURL *url1 = [NSURL URLWithString:@"www.baidu.com"];
NSURLRequest *request = [NSURLRequest requestWithURL:url1 cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:5];
NSHTTPURLResponse *response;
NSError * error;
[NSURLConnection sendSynchronousRequest:request returningResponse: &response error: &error];
查看一下错误对象的里面的内容,发现是域名出了问题,改成以下这样就可以了。
NSURL *url1 = [NSURL URLWithString:@"http://www.baidu.com/"];
NSURLRequest *request = [NSURLRequest requestWithURL:url1 cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:5];
NSHTTPURLResponse *response;
NSError * error;
[NSURLConnection sendSynchronousRequest:request returningResponse: &response error: &error];