NSString *urlStr = [NSString stringWithFormat:@"%@uploadFileRest/downFile",[AFAppDotNetAPIClient getUrl]];session
NSURL *url = [NSURL URLWithString:urlStr];async
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];post
request.HTTPMethod = @"POST";url
NSString *post = [NSString stringWithFormat:@"contentType=%@&fileName=%@&filePath=%@",model.CONTENT_TYPE,model.FILE_NAME,model.FILE_PATH];spa
request.HTTPBody = [post dataUsingEncoding:NSUTF8StringEncoding];orm
NSURLSession *session = [NSURLSession sharedSession];ip
// 能夠沒必要建立請求直接用url進行獲取,可是隻能應用於get請求get
NSURLSessionTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {string
if (error) {it
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:error.localizedDescription preferredStyle: UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"肯定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction *action) {
}];
[alert addAction:okAction];
//彈出提示框;
[self presentViewController:alert animated:true completion:nil];
}else
{
image1 = [UIImage imageWithData:data];
dispatch_async(dispatch_get_main_queue(), ^
{
// 更UI
UIImageView *imgView1 = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 200, 200)];
// imgView.backgroundColor = [UIColor yellowColor];
imgView1.image = image1;
[self.view addSubview:imgView1];
});
}
}];
[task resume];