Latest 1.3.2
Homepage https://github.com/zachariahlee/ZHNetworking
License MIT
Platforms ios 8.0, requires ARC
Dependencies AFNetworking
Frameworks Foundation
Authors

iOS网络操作:各种方式(GET、POST等)的请求、上传、下载

支持cocoapods导入

pod 'ZHNetworking'

使用前可以使用ZHHTTPConfig对请求进行配置

//一般为host,如果设置,request的url必须为去除host的部分,否则必须为完整的url
@property (nonatomic, copy) NSString *baseURL;
///超时时间,默认60s
@property (nonatomic, assign) NSTimeInterval requestTimeoutInterval;
///请求头
@property (nonatomic, copy) NSDictionary *httpHeaderField;
///https证书名称
@property (nonatomic, copy) NSString *cerName;
///代理
@property (nonatomic, weak) id<ZHHTTPConfigDelegate> delegate;
///配置https证书
- (AFSecurityPolicy *)configSecurityPolicy;

网络连接

[ZHHTTPReachability handlerNetworkReachable:^(BOOL reachable) {
    NSLog(@"网络连接:%d", reachable);
}];

请求

ZHHTTPRequest *request = [ZHHTTPRequest requestGET:@"https://www.apple.com"];
[ZHHTTPManager request:request success:^(id response) {

} failure:^(NSInteger statusCode, NSString *status) {

}];

模拟请求

ZHHTTPRequest *request = [ZHHTTPRequest requestGET:@"https://www.apple.com"];
request.mockResponse = @{};
[ZHHTTPManager request:request success:^(id response) {

} failure:^(NSInteger statusCode, NSString *status) {

}];

上传

UIImage *image = nil;
ZHHTTPRequest *request = [ZHHTTPRequest requestPOSTMultipart:@"https://www.apple.com" params:@{@"id":@123} multipartConstruct:^(id<AFMultipartFormData> formData) {
        [formData appendPartWithFileData:UIImageJPEGRepresentation(image, 1.0) name:@"file" fileName:@"20111111.jpg" mimeType:@"image/jpeg"];
    }];
[ZHHTTPManager request:request success:^(id response) {

} failure:^(NSInteger statusCode, NSString *status) {

}];

下载

//存储在Library
[ZHHTTPManager downloadWithURLString:@"" progress:^(CGFloat progress) {
    NSLog(@"下载进度:%.2lf", progress*100.0);
} success:^(NSURLResponse *response, NSURL *filePath) {

} failure:^(NSError *error) {

}];
//指定存储URL
[ZHHTTPManager downloadWithURLString:@"" progress:^(CGFloat progress) {
    NSLog(@"下载进度:%.2lf", progress*100.0);
} destination:^NSURL *(NSString *suggestedFilename) {
    return [NSURL URLWithString:@""];
} success:^(NSURLResponse *response, NSURL *filePath) {

} failure:^(NSError *error) {

}];

Latest podspec

{
    "name": "ZHNetworking",
    "version": "1.3.2",
    "summary": "iOSu7f51u7edcu64cdu4f5c",
    "description": "iOSu7f51u7edcu64cdu4f5cuff1au5404u79cdu65b9u5f0fuff08GETu3001POSTu7b49uff09u7684u8bf7u6c42u3001u4e0au4f20u3001u4e0bu8f7d",
    "homepage": "https://github.com/zachariahlee/ZHNetworking",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "zachariahlee": "[email protected]"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/zachariahlee/ZHNetworking.git",
        "tag": "1.3.2"
    },
    "source_files": "Pod/Classes/*.{h,m}",
    "frameworks": "Foundation",
    "requires_arc": true,
    "dependencies": {
        "AFNetworking": []
    }
}

Pin It on Pinterest

Share This