2 GET用法二:
5 RunLoop的主动释放池
- 第一次创建 RunLoop启动的时刻
- 最后一次 RunLoop退出的时刻
- 其它时光的创建和烧毁:当RunLoop即将休眠的时刻会把之前的主动释放池烧毁,从新创建一个新的
3 GET1和GET2的差别是根据会话对象创建task不合,其实用法照样一样的.
4 POST用法:
- - (void)get1
- {
- //肯定请求路径
- NSURL *url = [NSURL URLWithString:@"http://120.25.226.186:32812/login?username=520it&pwd=520it&type=JSON"];
- //创建请求对象
- // NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
- //创建会话对象
- NSURLSession *session = [NSURLSession sharedSession];
- //根据会话对象创建task
- NSURLSessionDataTask *dataTask = [session dataTaskWithURL:url completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
- NSLog(@"%@",[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
- //该block块是在子线程中调用
- NSLog(@"%@",[NSThread currentThread]);
- }];
- //开启task
- [dataTask resume];
- }
- - (void)post
- {
- //肯定请求路径
- NSURL *url = [NSURL URLWithString:@"http://120.25.226.186:32812/login"];
- //创建可变的请求对象
- NSMutableURLRequest *resquest = [NSMutableURLRequest requestWithURL:url];
- //转换格局
- resquest.HTTPMethod = @"POST";
- //设置请求体信息
- resquest.HTTPBody = [@
推荐阅读
沙龙晃荡 | 3月31日 京东、微博、华为拭魅战专家与你合营商量容器技巧实践! 所谓边沿数据中间,指的就是:处于>>>详细阅读
本文标题:iOS开发3年只用5分钟搞定面试官
地址:http://www.17bianji.com/lsqh/40950.html
1/2 1