AFNetworking 3.0 的基础使用
//参数
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
NSString *md5String = [MyMD5 md5StringNB:@"xxxxxx"];
[dic setValue:md5String forKey:@"requestToken"];
//请求数据的网址
NSString *urlString = [NSString stringWithFormat:@"http://xxxxxxxxxxxxxx"];
//创建单例对象(在AFNetworking 3.0以后使用该方法)
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
//序列化
manager.requestSerializer = [AFHTTPRequestSerializer serializer];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
[manager POST:urlString parameters:dic success:^(NSURLSessionDataTask * _Nonnull task, id _Nonnull responseObject) {
NSLog(@"请求数据成功");
NSLog(@"responseObject>>>\n%@",responseObject);
/*
最终打印出的responseObject数据是这样的的:
<7b227265 73756c74 64617461 223a7b22 6c617722 3a5b7b22 6964223a 22423134 45363737 372d4342 35442d34 3443352d 39423041 2d334631>
*/
//对json格式数据进行解析
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves error:nil];
NSLog(@"dict>>>\n%@",dict);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"请求数据失败");
}];