VNHttpRequest 1.0.1

VNHttpRequest 1.0.1

guohongqi 维护。



  • 作者:
  • guohongqi-china

VNHttpRequest 特点

  • 对 AFNetworking 进行二次封装,对响应数据进行进一步解析。防止出现二进制数据,对分析问题造成阻碍。
  • 对 get、post、delete、put、patch、HEAD 等方法进行进一步封装。
  • 将请求任务放入队列中进行管理,最大并发数为 6。
  • 对请求头进行进一步封装。并解析响应头数据,后台数据并不都通过 body 返回。
  • 对 JSON、FORM-DATA 两种请求作区分。
  • 简书地址

安装

CocoaPods

  1. pod 'VNHttpRequest' 添加到您的 Podfile 中。
  2. 运行 pod installpod update
  3. 导入 <VNHttpRequest/VNHttpRequest.h>。

使用案例

创建一个请求 get

[VNHttpRequestManager sendJSONRequestWithMethod:RequestMethod_Get pathUrl:@"https://westus.api.cognitive.microsoft.com/spid/v1.0/identificationProfiles" params:nil complement:^(ServerResponseInfo *serverInfo) {
if (serverInfo.isSuccess) {
self.itemArr = [serverInfo.response mutableCopy];
}
}];

创建一个请求帖子

[VNHttpRequestManager sendJSONRequestWithMethod:RequestMethod_Post pathUrl:@"https://westus.api.cognitive.microsoft.com/spid/v1.0/identificationProfiles/" params:@{@"locale":@"en-us"} complement:^(ServerResponseInfo *serverInfo) {
if (serverInfo.isSuccess) {

}
}];

创建一个表单数据 提参方式

[VNHttpRequestManager sendFORMRequestWithMethod:RequestMethod_Post pathUrl:@"https://westus.api.cognitive.microsoft.com/spid/v1.0/identificationProfiles/" params:@{@"key":@"value"} complement:^(ServerResponseInfo * _Nullable serverInfo) {

}];

创建一个上传数据

[VNHttpRequestManager uploadFileWithPath:@"https://westus.api.cognitive.microsoft.com/spid/v1.0/identificationProfiles/28277c34-9512-4b89-97af-3a3683172287/enroll?shortAudio=true" filePath:@[@"/Users/用户/Desktop/xxxx.wav"] parms:nil fileType:FileType_Video result:^(ServerResponseInfo *serverInfo) {
if (serverInfo.isSuccess) {
[self.itemArr removeObjectAtIndex:0];
}
}];

创建一个下载

downTask =  [VNHttpRequestManager downLoadRequest:@"http://dldir1.qq.com/qqfile/QQforMac/QQ_V5.4.0.dmg"  filePath:nil downProgress:^(double progress) {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
NSLog(@"%f",progress);
}];
} complement:^(NSURLResponse * _Nonnull response, NSURL * _Nullable filePath, NSError * _Nullable error) {

}];

# 开始/恢复下载
[VNHttpRequestManager startResume:downTask];
# 暂停下载
[VNHttpRequestManager suspend:downTask];