五 POST方法
1 直接看代码,膳绫擎都标清楚明了
- - (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent *)event
- {
- //创建请求路径
- NSURL *url = [NSURL URLWithString:@"http://120.25.226.186:32812/login"];
- //创建可变的请求对象
- NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
- //修改请求方法
- request.HTTPMethod = @"POST";
- //设置请求超时
- request.timeoutInterval = 10;
- NSURLResponse *response = nil;
- NSError *error = nil;
- //设置请求头信息
- [request setValue:@"jjjj" forHTTPHeaderField:@"uuuuu"];
- //设置请求体(参数)
- request.HTTPBody = [@"username=520it&pwd=520it&type=JSON" dataUsingEncoding:NSUTF8StringEncoding];
- //第一种办法:发送请求(异步请求)
- [NSURLConnection sendAsynchronousRequest:request queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
- //解析数据
- if (connectionError == nil) {
推荐阅读
沙龙晃荡 | 3月31日 京东、微博、华为拭魅战专家与你合营商量容器技巧实践! 所谓边沿数据中间,指的就是:处于>>>详细阅读
本文标题:iOS开发3年只用5分钟搞定面试官
地址:http://www.17bianji.com/lsqh/40950.html
1/2 1