1. HTTPS 證書認證(導入相關證書)
2. 發(fā)送請求
[[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. 請求實例
【鏈接】https://github.com/MrJalen/AFNet3.0
版權聲明:本文為博主原創(chuàng)文章,未經(jīng)博主允許不得轉載。