iOS笔记—NSURLConnection怎么把http改为https
来源:互联网 发布:俄罗斯残奥会禁赛知乎 编辑:程序博客网 时间:2024/05/17 05:57
一直使用NSURLConnection请求HTTP接口,现在为了安全性的考虑打算使用HTTPS。
那么怎么修改呢?
1.不需要证书验证 ps:我们使用的就是这种
1.1 直接修改HTTP为HTTPS;
1.2 确认有 “Security.framework”
1.3 修改完成,可以直接请求了。
2.需要证书验证
其他的和1是一样的,只不过需要加下面方法.
- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge{ static CFArrayRef certs; if (!certs) { NSData*certData =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"srca" ofType:@"cer"]]; SecCertificateRef rootcert =SecCertificateCreateWithData(kCFAllocatorDefault,CFBridgingRetain(certData)); const void *array[1] = { rootcert }; certs = CFArrayCreate(NULL, array, 1, &kCFTypeArrayCallBacks); CFRelease(rootcert); // for completeness, really does not matter } SecTrustRef trust = [[challenge protectionSpace] serverTrust]; int err; SecTrustResultType trustResult = 0; err = SecTrustSetAnchorCertificates(trust, certs); if (err == noErr) { err = SecTrustEvaluate(trust,&trustResult); } CFRelease(trust); BOOL trusted = (err == noErr) && ((trustResult == kSecTrustResultProceed)||(trustResult == kSecTrustResultConfirm) || (trustResult == kSecTrustResultUnspecified)); if (trusted) { [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge]; }else{ [challenge.sender cancelAuthenticationChallenge:challenge]; }}
0 0
- iOS笔记—NSURLConnection怎么把http改为https
- NT_iOS笔记—NSURLConnection怎么把http改为https
- NSURLConnection怎么把http改为https
- 把Tomcat的http改为https的步骤、方法
- iOS学习笔记(八)——iOS网络通信http之NSURLConnection
- iOS学习笔记(八)——iOS网络通信http之NSURLConnection
- iOS学习笔记(八)——iOS网络通信http之NSURLConnection
- iOS学习笔记(八)——iOS网络通信http之NSURLConnection
- iOS学习笔记(八)——iOS网络通信http之NSURLConnection
- 在Nginx中,怎么把http全转发为https
- iOS UIWebView 加载https 站点出现NSURLConnection/CFURLConnection HTTP load failed (kCFStreamErrorDomainSSL,
- iOS UIWebView 加载https 站点出现NSURLConnection/CFURLConnection HTTP load failed (kCFStreamErrorDomainSSL,
- 怎么把pdf首页改为其他页面
- ios web interface 改为https接口
- iOS-Network学习笔记(二)——NSURLConnection
- iOS: NSUrlConnection & SSL, Http connection frameworks
- iOS网络通信http之NSURLConnection
- iOS网络通信http之NSURLConnection
- Java基础泛型篇一
- JQuery中ajax处理跨域的三大方式
- Hibernate与Ibatis比较
- 以Yii 2.0风格加载自定义类或命名空间 [配置使用Yii autoloader] [ 2.0 版本 ]
- Python数据类型转换
- iOS笔记—NSURLConnection怎么把http改为https
- 腾正科技“护驾”来袭
- log4j详细配置
- 从零开始构建MSBuild C#项目文件
- Intent和IntentFilter详解
- Java中的继承
- 获取当前屏幕显示的viewcontroller
- 15.0坂本Nios ii 编译on_chip_memory过小的解决方案
- sqlite的数据库