这是一个使 HttpRequests 和 NSURLRequest 类别支持自定义头和文件的分装器。除了其他功能外,该网络服务还具有忽略无效 SSL 证书(通过设置受信任的主机)的能力。它还使用块来跟踪请求的成功响应数据、失败或请求的进度百分比。
DTWebService
文件夹到您的项目中的方法pod 'DTWebService'
添加到 Podfile。示例 1:发送简单请求(将 sendAsyncRequest:
改为 sendTrustedRequest:
将忽略任何无效的 SSL 证书)
[DTWebService sendAsyncRequest:request finishedBlock:^(NSData *data, NSStringEncoding stringEncoding) { // handle completion } fail:^(NSError *error, BOOL cancelled) { // handle failure } progress:^(float progressPercentage) { // handle progress (update ui etc.) }];
示例 2:发送可取消的请求
DTWebService *webService = [[DTWebService alloc] initWithURL:[NSURL URLWithString:@"a url..."]]; [webService startWithFinishedBlock:^(NSData *data, NSStringEncoding stringEncoding) { } fail:^(NSError *error, BOOL cancelled) { } progress:^(float progressPercentage) { }]; .... [webService stop]; // stop/cancel the request