Asynchronously with NSURLConnection
NSString *urlAsString=@"http://www.apple.com"; NSURL *url=[NSURL URLWithString:urlAsString]; NSURLRequest *urlRequest=[NSURLRequest requestWithURL:url]; NSOperationQueue *queue=[[NSOperationQueue alloc]init]; [NSURLConnection sendAsynchronousRequest:urlRequest queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { if ([data length]>0 && error==nil) { NSString *html=[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]; NSLog(@"Html is %@",html); }else if([data length]==0 && error ==nil){ NSLog(@"Nothing was downloaded!"); }else if(error !=nil){ NSLog(@"Error happeded! %@",error); } }];
posted on 2013-11-07 23:02 Ijavascript 阅读(170) 评论(0) 编辑 收藏 举报