// 网络加载标志
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
// 请求参数数据
NSError *error = nil;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error];
// 创建配置信息
NSURLSessionConfiguration *configure = [NSURLSessionConfiguration defaultSessionConfiguration];
configure.timeoutIntervalForRequest = 10;// 设置超时时间
// 创建会话
NSURLSession *session = [NSURLSession sessionWithConfiguration:configure delegate:nil delegateQueue:[NSOperationQueue mainQueue]];
// 请求
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/report/upload",Host_Name]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10];
[request addValue:@"raw" forHTTPHeaderField:@"Content-Type"];// 设置请求类型
[request setHTTPMethod:@"POST"];// 设置请求方法
[request setHTTPBody:jsonData];// 设置请求参数
NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
// 网络加载标志
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
if (error == nil) {
NSDictionary *object = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
NSLog(@"✅生成pdf.....%@",object);
callback(object,nil);
} else {
NSLog(@"生成pdf❌.....%@",error);
failed(K__ERROR);
}
}];
[task resume];
网友评论