AFNetworking3.0 POST请求

 1  // 请求管理者
 2     AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
 3     manager.responseSerializer = [AFHTTPResponseSerializer serializer];
 4     
 5     
 6     // 拼接请求参数
 7     NSMutableDictionary *params = [NSMutableDictionary dictionary];
 8     params[@"client_id"] = @"2331570398";
 9     params[@"client_secret"] = @"240608336b729e27685af0ec496c1a60";
10     params[@"grant_type"] = @"authorization_code";
11     params[@"redirect_uri"] = @"http://";
12     params[@"code"] = code;
13 
14 
15     
16     
17     [manager POST:@"https://api.weibo.com/oauth2/access_token" parameters:params progress:^(NSProgress * _Nonnull uploadProgress) {
18         
19     } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
20         NSLog(@"请求成功:%@", responseObject);
21         
22         NSDictionary *JSON = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
23         
24         NSLog(@"请求成功JSON:%@", JSON);
25 
26         
27     } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
28         
29         NSLog(@"请求失败:%@", error.description);
30 
31     }];
32     

 

posted @ 2016-01-03 16:58  TianXiang.Liu  阅读(622)  评论(0编辑  收藏  举报