1. HTTPS 证书认证(导入相关证书)
证书认证代码.png2. 发送请求
[[AFNetAPIClient sharedJsonClient].setRequest(@"getjobs").RequestType(GET).Parameters(@{@"pagenum":@(1)}) startRequestWithSuccess:^(NSURLSessionDataTask *task, id responseObject) { NSLog(@"Success");
} progress:^(NSProgress *progress) {
NSLog(@"%@",progress);
} failure:^(NSURLSessionDataTask *task, NSError *error) {
NSLog(@"%@",error);
}];
3. 下载文件
[[AFNetAPIClient sharedJsonClient].setRequest(@"http://120.25.226.186:32812/resources/videos/minion_02.mp4") downloadWithSuccess:^(NSURLResponse *response, NSURL *filePath) { NSLog(@"Success");
} progress:^(NSProgress *progress) {
NSLog(@"%@",progress);
} failure:^(NSURLSessionDataTask *task, NSError *error) {
NSLog(@"%@",error);
}];
4.上传图片
UIImage *img = [UIImage imageNamed:@"1"];
NSData *data = UIImageJPEGRepresentation(img, 0.5);
NSDictionary *dic = @{@"timestamp" : @"1457403110", @"file" : data, @"xtype" :@"bang_album", @"token" : @"8a3dead8022c6c85248efca767c9ecfaf8836617"};
[[AFNetAPIClient sharedJsonClient].setRequest(@"upload.php").Parameters(dic).filedata(data).name(@"Filedata").filename(@"Filedata.jpg").mimeType(@"image/jpeg") uploadfileWithSuccess:^(NSURLSessionDataTask *task, id responseObject) { NSLog(@"Success");
} progress:^(NSProgress *progress) {
NSLog(@"%@",progress);
} failure:^(NSURLSessionDataTask *task, NSError *error) {
NSLog(@"%@",error);
}];
5. 请求实例
代码请求实例.png【链接】https://github.com/MrJalen/AFNet3.0
版权声明:本文为博主原创文章,未经博主允许不得转载。
网友评论