/QSHttp-ObjC

该仓库为iOS封装简单易用的请求框架

Primary LanguageObjective-CMIT LicenseMIT

image

Build Status License language language

概述

为简化后期的手机客户端与服务器调试,特此对各个环境进行了封装,本仓库为iOS版本,其它有Java(安卓通用)版本、服务器版本。

特点

  • 采用多线程异步请求机制
  • 支持请求的URL带有中文

进度

  • 完成基本的GET、POST、上传、下载、等操作
  • 完成delegate向block的转换
  • 完成上传、下载的实时进度

安装方法

使用cocoapods:

pod 'QSHttp-OC', '~> 1.1.1'

使用方法

GET方法示例:

- (void)get_http {
    
    QSHttpManage *mange = [[QSHttpManage alloc] init];
    [mange GET:@"http://www.eechot.ga/server/QSHttp/GET/天气" param:nil success:^(id  _Nonnull rspObject) {
        NSLog(@"响应数据  %@", rspObject);
    } failure:^(NSError * _Nonnull error) {
        NSLog(@"失败 %@", error);
    }];
}

POST方法示例:

- (void)post_http {
    
    QSHttpManage *mange = [[QSHttpManage alloc] init];
    [mange POST:@"http://www.eechot.ga/server/QSHttp/POST" param:nil success:^(id  _Nonnull rspObject) {
        NSLog(@"响应数据  %@", rspObject);
    } failure:^(NSError * _Nonnull error) {
        NSLog(@"失败 %@", error);
    }];
}

download下载文件示例:

- (void)download_http {
    
    QSHttpManage *mange = [[QSHttpManage alloc] init];
    [mange download:@"http://www.eechot.ga/server/QSHttp/Download" param:nil storagePath:@"/Users/yyd-wlf/Desktop/QSHttpFile" progress:^(float progress) {
        
        int progressInt = progress * 100;
        NSLog(@"下载进度 %d%%", progressInt);
        
    } success:^(id  _Nonnull rspObject) {
        NSLog(@"响应数据  %@", rspObject);
    } failure:^(NSError * _Nonnull error) {
        NSLog(@"失败 %@", error);
    }];
}

upload上传数据(NSData)示例:

- (void)uploadData_http {
    
    QSHttpManage *mange = [[QSHttpManage alloc] init];
    NSData *data = [NSData dataWithContentsOfFile:@"/Users/yyd-wlf/Desktop/QSHttpFile/nginx-1.16.0.tar.gz"];
    [mange upload:@"http://www.eechot.ga/server/QSHttp/Upload" fileData:data progress:^(float progress) {
        
        int progressInt = progress * 100;
        NSLog(@"上传进度 %d%%", progressInt);
        
    } success:^(id  _Nonnull rspObject) {
        NSLog(@"响应数据  %@", rspObject);
    } failure:^(NSError * _Nonnull error) {
        NSLog(@"失败 %@", error);
    }];
}

upload上传文件示例:

- (void)uploadFile_http {
    
    QSHttpManage *mange = [[QSHttpManage alloc] init];
    [mange upload:@"http://www.eechot.ga/server/QSHttp/Upload" filePath:@"/Users/yyd-wlf/Desktop/QSHttpFile/nginx-1.16.0.tar.gz" progress:^(float progress) {
        
        int progressInt = progress * 100;
        NSLog(@"上传进度 %d%%", progressInt);
        
    } success:^(id  _Nonnull rspObject) {
        NSLog(@"响应数据  %@", rspObject);
    } failure:^(NSError * _Nonnull error) {
        NSLog(@"失败 %@", error);
    }];
}

许可证

所有源代码均根据MIT许可证进行许可。