//创建
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
//请求格式manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/json",@"application/json",@"text/javascript",@"text/html", nil];
//post请求[manager POST:URL parameters:body progress:^(NSProgress * _Nonnull uploadProgress) {
// 此处为上传的进度,uploadProgress.fractionCompleted
// 此处为异步请求,必须回到主线程刷新UI
dispatch_sync(dispatch_get_main_queue(), ^{
//Update UI in UI thread here
[[NSNotificationCenter defaultCenter] postNotificationName:noti object:@{noti : [NSString stringWithFormat:@"%f",uploadProgress.fractionCompleted]}];
});
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
//请求成功
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
// 请求失败
}
application.networkActivityIndicatorVisible = NO;
}];