The following is the line of code that I have used for http request. On running the simulator I only get the “connecting as displayed” .. can someone help me with the right code so as to display the google homepage. thanks.
- (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;
}
try this