zoukankan      html  css  js  c++  java
  • 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);
            }
        }];
  • 相关阅读:
    android作业10.21
    安卓10.7作业
    安卓9.30
    9.23作业
    9.17安卓作业
    6.12作业
    5.29作业
    5.28上机作业
    leetcode 219
    策略模式
  • 原文地址:https://www.cnblogs.com/wangwenfei/p/nsurlconnection.html
Copyright © 2011-2022 走看看