作家
登录

iOS开发3年只用5分钟搞定面试官

作者: 来源: 2018-03-27 12:52:54 阅读 我要评论

  •   
  •     //肯定url 
  •     NSURL *url = [NSURL URLWithString:urlstr]; 
  •   
  •     //创建请求对象 
  •     NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; 
  •   
  •     //转为POST格局 
  •     request.HTTPMethod = @"POST"
  •     //转码 
  •     request.HTTPBody = [@"username=(须要转的汉字)&pwd=520it&type=JSON" dataUsingEncoding:NSUTF8StringEncoding ]; 
  •     NSURLResponse *response = nil; 
  •     NSError *error = nil; 
  •   
  •     //发送请求(同步请求) 
  •     NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; 
  •     //解析数据 
  •     NSLog(@"%@",[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]); 
  •   
  •     //发送请求(异步请求) 
  •     [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) { 
  •         //解析数据 
  •         if (connectionError == nil) { 
  •             NSLog(@"%@",[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]); 
  •         }else
  •             NSLog(@"%@",connectionError); 
  •         } 
  •   
  •     }];     
  • 七 NSURLSession简单应用

    1 NSURLSession —->GET用法:

    1. - (void)get 
    2.     //肯定请求路径 
    3.     NSURL *url = [NSURL URLWithString:@"http://120.25.226.186:32812/login?username=520it&pwd=520it&type=JSON"]; 
    4.     //创建请求对象 
    5.     NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url ]; 
    6.     //获取会话对象(是一个单例) 
    7.     NSURLSession *session = [NSURLSession sharedSession]; 
    8.   
    9.     //根据会话对象创建task 
    10.     /** 
    11.      *  参数一:请求对象 
    12.      * 
    13.      *  参数二:响应头response信息;响应体data信息;error缺点信息 
    14.      * 
    15.      * 

        推荐阅读

        2018边缘数据中心关键之年!

      沙龙晃荡 | 3月31日 京东、微博、华为拭魅战专家与你合营商量容器技巧实践! 所谓边沿数据中间,指的就是:处于>>>详细阅读


      本文标题:iOS开发3年只用5分钟搞定面试官

      地址:http://www.17bianji.com/lsqh/40950.html

    关键词: 探索发现

    乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

    网友点评
    自媒体专栏

    评论

    热度

    精彩导读
    栏目ID=71的表不存在(操作类型=0)