ios项目绕过证书访问https程序
如果是单个的webview或者request请求,在请求的文件h中直接实现NSURLConnectionDelegate,并在m中添加下列实现下列两个方法:
- - (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
- return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
- }
- - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
- if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])
- //if ([trustedHosts containsObject:challenge.protectionSpace.host])
- [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]
- forAuthenticationChallenge:challenge];
- [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
- }
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])
//if ([trustedHosts containsObject:challenge.protectionSpace.host])
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]
forAuthenticationChallenge:challenge];
[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}
上述方法很不爽的是每个请求的地方都要加。
如果项目中用到了three20,直接修改“TTRequestLoader.m”即可,这个文件本身就已经实现了NSURLConnectionDelegate,
修改如下,只改这一个地方就行,处处可用。
- ///////////////////////////////////////////////////////////////////////////////////////////////////
- - (void)connection:(NSURLConnection *)connection
- didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge{
- //修改
- if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])
- [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
- [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
- TTDCONDITIONLOG(TTDFLAG_URLREQUEST, @" RECEIVED AUTH CHALLENGE LOADING %@ ", _urlPath);
- [_queue loader:self didReceiveAuthenticationChallenge:challenge];
- }
- //添加
- - (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
- return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
- }
///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)connection:(NSURLConnection *)connection
didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge{
//修改
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge]; TTDCONDITIONLOG(TTDFLAG_URLREQUEST, @" RECEIVED AUTH CHALLENGE LOADING %@ ", _urlPath);
[_queue loader:self didReceiveAuthenticationChallenge:challenge];
} //添加
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}
ios项目绕过证书访问https程序的更多相关文章
- iOS 安全:UIWebView访问Https站点防止中间人攻击
尽管Https协议能够提供数据的加密.身份的认证等安全服务,但并不是没有漏洞.HTTPS协议安全隐患的存在可能使用户受到各种极具破坏力的网络攻击.其中中间人攻击(Man In The Middle, ...
- Https:Java代码设置使用证书访问Https
设置证书进行访问或被访问操作 String keyStore = "keyStore的文件路径": String KEY_STORE_PWD = "1234"; ...
- Java实现 HTTP/HTTPS请求绕过证书检测
java实现 HTTP/HTTPS请求绕过证书检测 一.Java实现免证书访问Https请求 创建证书管理器类 import java.security.cert.CertificateExcepti ...
- httpclient 无信任证书使用https
1.当不需要使用任何证书访问https网页时,只需配置信任任何证书 HttpClient http = new HttpClient(); String url = "https://pay ...
- WebClient 访问https
解决SSH证书问题: webClient.getOptions().setUseInsecureSSL(true);//解决ssh证书访问https的问题
- httpClient无证书访问
1.当不需要使用任何证书访问https网页时,只需配置信任任何证书 HttpClient http = new HttpClient(); String url = "https://pay ...
- iOS使用自签名证书实现HTTPS请求
概述 在16年的WWDC中,Apple已表示将从2017年1月1日起,所有新提交的App必须强制性应用HTTPS协议来进行网络请求. 默认情况下非HTTPS的网络访问是禁止的并且不能再通过简单粗暴的向 ...
- iOS 用自签名证书实现 HTTPS 请求的原理
在16年的WWDC中,Apple已表示将从2017年1月1日起,所有新提交的App必须强制性应用HTTPS协议来进行网络请求.默认情况下非HTTPS的网络访问是禁止的并且不能再通过简单粗暴的向Info ...
- 使用poco 的NetSSL_OpenSSL 搭建https 服务端,使用C++客户端,java 客户端访问,python访问(python还没找到带证书访问的代码.)
V20161028 由于项目原因,需要用到https去做一些事情. 这儿做了一些相应的研究. 这个https 用起来也是折腾人,还是研究了一周多+之前的一些积累. 目录 1,java client 通 ...
随机推荐
- a different object with the same identifier value was already associated withthe session异常解决方案
异常信息: org.hibernate.NonUniqueObjectException: a different object with the same identifier value was ...
- VS平台工具集版本
参考:http://blog.csdn.net/hillseas/article/details/47373313 VS从2010之后开始支持使用之前的版本进行编译,可以在工程属性->常规中进行 ...
- 写过的HTML标签(一)
HTML > 标题显示字体大小为<h1>. HTML 段落是通过标签 <p> 来定义的. HTML 链接是通过标签 <a> 来定义的. 实例: < ...
- 第二章 Background & Borders 之 Multiple borders
2. Multiple Boerders 多边框 在工作中我们可能会遇到给盒子外层实现多个边框.如以下效果: 方法1: 实现这个效果,其实很简单,使用CSS3 的box-shadow属性,先看看box ...
- 使 div 元素看上去像一个按钮
使 div 元素看上去像一个按钮 div { appearance:button; -moz-appearance:button; /* Firefox */ -webkit-appearance:b ...
- Android 手势滑动,多点触摸放大缩小图片
效果展示: 基本思路: <1>首先写一个图片控制类ImageControl,实现对图片控制的的基本操作,我们的图片控制类ImageControl是继承自ImageView自定义的视图: & ...
- MySQL Server 5.5安装中遇到的问题及解决方法
之前开始用师兄用过的电脑工作,各种不适应,开始重新搭建自己习惯的环境,重装MySQL就是其中一项,然后重装过程中遇到了问题,具体情况总结如下: 1.以前也重新安装过MySQL,但是完全没有用过就直接卸 ...
- 运行第一个Node.js程序
初学Node.js,萌新一枚.感觉Node.js挺不错的,从基础开始一步一步来,加油吧! 我们来使用Node.js的express来运行第一个程序helloworld: 在命令提示符键入express ...
- xenserver xensource.log不断增长
转载:http://blog.sina.com.cn/s/blog_4ca83f830100xded.html 相信很多人被Xenserver日志填满磁盘空间,导致机器最终挂掉的问题所困扰,我 ...
- 在iOS中,实现点击搜索结果隐藏搜索结果的方法。
不知道有没有别的什么的好的方法,最近在实现一个需求(点击搜索,然后输入搜索内容,显示搜索出来的结果,然后点击搜索结果,在当前页面显示所点击的结果的详细的信息).遇到的问题是,点击搜索结果的时候,搜索的 ...