以下是我用于 http 请求的代码行。在运行模拟器时,我只得到“显示的连接”.. 有人可以帮助我使用正确的代码以显示谷歌主页。谢谢。
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http:www.google.com"] cachePolicy: NSURLRequestUseProtocolCachePolicy timeoutInterval: 15.0];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest: request delegate:self];
if(connection){
//connect
label.text = @"connecting .....";
}else{
//error
}
}
-(void) connection: (NSURLConnection *)conenction didReceiveData:(NSData *)data{
response = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
}
-(void) connectionDidFinishLoading:(NSURLConnection *)connection{
connection = nil;
}