标签:
// // ViewController.m // 01 AFN基本使用 // // Created by kun on 16/8/14. // Copyright © 2016年 kun. All rights reserved. // #import "ViewController.h" #import "AFNetworking.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { [self get]; } - (void)get { // 创建会话管理者 AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; manager.responseSerializer = [AFHTTPResponseSerializer serializer]; // 创建参数 NSDictionary *parameters = @{ @"username" : @"123", @"pwd" : @"123", @"type" : @"JSON" }; // 发送GET请求 /* 第一个参数:请求路径(不包含参数)NSString 第二个参数:字典(发送给服务器的数据-参数) 第三个参数:progress进度回调 第四个参数:success成功回调 task:请求任务 responseObject:响应信息(->OC对象) 第五个参数:failure失败回调 error:错误信息 响应头:task.response */ [manager GET:@"http://www.baidu.com" parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { NSLog(@"%@---%@", [responseObject class], responseObject); } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { NSLog(@"failure---%@", error); }]; // } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
标签:
原文地址:http://www.cnblogs.com/fkunlam/p/5770059.html