zoukankan      html  css  js  c++  java
  • NSURLSession

    - (IBAction)login:(UIButton *)sender {

        

        NSString *username = self.usrnameTextField.text;

        NSString *password = self.pwdTextField.text;

        

        

        NSString *urlStr =[NSString stringWithFormat:@"http://qzone.qq.com/login?username=%@&pwd=%@",username,password];

        

        urlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

        

        NSURL *url = [NSURL URLWithString:urlStr];

        

        NSURLRequest *request = [NSURLRequest requestWithURL:url];

        

        

        NSURLSessionConfiguration * configuration =[NSURLSessionConfiguration defaultSessionConfiguration];

        

        NSURLSession *session =[NSURLSession sessionWithConfiguration:configuration];

    //创建一个任务

        NSURLSessionDataTask *task =[session dataTaskWithRequest:request completionHandler:^(NSData *data,    NSURLResponse *response, NSError *error) {

            

            NSLog(@"服务器返回了%d个字节的数据",data.length);

            NSString * datastr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];

            NSLog(@"内容%@",datastr);

        

        }];

       //启动

        [task resume];

    }

  • 相关阅读:
    复杂网络研究的委员老师信息总合
    numpy读取本地数据和索引
    numpy数组的计算
    numpy数组的创建
    python画图的工具及网站
    matplotlib直方图
    matplotlib.legend()函数用法
    matplotlib条形图
    matplotlib散点图
    matplotlib折线图
  • 原文地址:https://www.cnblogs.com/appshan/p/4569035.html
Copyright © 2011-2022 走看看