HTTPS链式编程(AF 3.0)

1. HTTPS 证书认证(导入相关证书)

证书认证代码.png

2. 发送请求

[[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


版权声明:本文为博主原创文章,未经博主允许不得转载。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容