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);
        }
    }];
原文地址:https://www.cnblogs.com/wangwenfei/p/nsurlconnection.html