如果是单个的webview或者request请求,在请求的文件h中直接实现NSURLConnectionDelegate,并在m中添加下列实现下列两个方法:

  1. - (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
  2. return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
  3. }
  4. - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
  5. if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])
  6. //if ([trustedHosts containsObject:challenge.protectionSpace.host])
  7. [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]
  8. forAuthenticationChallenge:challenge];
  9. [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
  10. }
- (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,

修改如下,只改这一个地方就行,处处可用。

  1. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2. - (void)connection:(NSURLConnection *)connection
  3. didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge{
  4. //修改
  5. if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])
  6. [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
  7. [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
  8. TTDCONDITIONLOG(TTDFLAG_URLREQUEST, @"  RECEIVED AUTH CHALLENGE LOADING %@ ", _urlPath);
  9. [_queue loader:self didReceiveAuthenticationChallenge:challenge];
  10. }
  11. //添加
  12. - (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
  13. return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
  14. }
///////////////////////////////////////////////////////////////////////////////////////////////////
- (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程序的更多相关文章

  1. iOS 安全:UIWebView访问Https站点防止中间人攻击

    尽管Https协议能够提供数据的加密.身份的认证等安全服务,但并不是没有漏洞.HTTPS协议安全隐患的存在可能使用户受到各种极具破坏力的网络攻击.其中中间人攻击(Man In The Middle, ...

  2. Https:Java代码设置使用证书访问Https

    设置证书进行访问或被访问操作 String keyStore = "keyStore的文件路径": String KEY_STORE_PWD = "1234"; ...

  3. Java实现 HTTP/HTTPS请求绕过证书检测

    java实现 HTTP/HTTPS请求绕过证书检测 一.Java实现免证书访问Https请求 创建证书管理器类 import java.security.cert.CertificateExcepti ...

  4. httpclient 无信任证书使用https

    1.当不需要使用任何证书访问https网页时,只需配置信任任何证书 HttpClient http = new HttpClient(); String url = "https://pay ...

  5. WebClient 访问https

    解决SSH证书问题: webClient.getOptions().setUseInsecureSSL(true);//解决ssh证书访问https的问题

  6. httpClient无证书访问

    1.当不需要使用任何证书访问https网页时,只需配置信任任何证书 HttpClient http = new HttpClient(); String url = "https://pay ...

  7. iOS使用自签名证书实现HTTPS请求

    概述 在16年的WWDC中,Apple已表示将从2017年1月1日起,所有新提交的App必须强制性应用HTTPS协议来进行网络请求. 默认情况下非HTTPS的网络访问是禁止的并且不能再通过简单粗暴的向 ...

  8. iOS 用自签名证书实现 HTTPS 请求的原理

    在16年的WWDC中,Apple已表示将从2017年1月1日起,所有新提交的App必须强制性应用HTTPS协议来进行网络请求.默认情况下非HTTPS的网络访问是禁止的并且不能再通过简单粗暴的向Info ...

  9. 使用poco 的NetSSL_OpenSSL 搭建https 服务端,使用C++客户端,java 客户端访问,python访问(python还没找到带证书访问的代码.)

    V20161028 由于项目原因,需要用到https去做一些事情. 这儿做了一些相应的研究. 这个https 用起来也是折腾人,还是研究了一周多+之前的一些积累. 目录 1,java client 通 ...

随机推荐

  1. find 忽略文件夹选项-prune的说明

    注意:因为习惯在当前路径查找时候,常忽略./ 的指定,但读者不要因此而完全忘记find的格式. 查找时忽略指定目录,是要使用-prune选项,但实际上最重要的还是要和path配合.-prune的意义是 ...

  2. HDU 4441 Queue Sequence

    http://acm.hdu.edu.cn/showproblem.php?pid=4441 题意:对于一个序列,每次有三种操作   insert pos  表示在pos插入一个数,这个数是最小的正数 ...

  3. 推荐5款超实用的.NET性能分析工具 转

    http://www.csdn.net/article/2012-11-23/2812174-5-Good-and-useful-.NET-Profilers

  4. 如何安装 JAVA 7 (JDK 7u75) 在 CentOS/RHEL 7/6/5 Fedora

    先下载JDK For 64 Bit:- # cd /opt/ # wget --no-cookies --no-check-certificate --header "Cookie: gpw ...

  5. C#时间格式 tostring、toshortdatestring、toshorttimestring

    在c#语言中的时间处理有几种方式: 首先获取当前时间:var date=new DateTime.Now; date.ToString()----2111-1-20 11:44:47 date.ToS ...

  6. 升级ionic版本后,创建新项目报Error Initializing app错误解决

    命令行,进入项目路径后,运行 ionic start myApp --v2 命令执行后,报如下错误 Installing npm packages...Error with start undefin ...

  7. 常见web服务器错误

    参考地址:http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.5     10 Status Code Definitions ...

  8. 济南学习 Day 5 T1 pm

    欧拉函数(phi)题目描述: 已知(N),求phi(N). 输入说明: 正整数N. 输出说明: 输出phi(N). 样例输入: 8 样例输出: 4 数据范围: 对于20%的数据,N<=10^5 ...

  9. 洛谷 P3374 【模板】树状数组 1

    题目描述 如题,已知一个数列,你需要进行下面两种操作: 1.将某一个数加上x 2.求出某区间每一个数的和 输入输出格式 输入格式: 第一行包含两个整数N.M,分别表示该数列数字的个数和操作的总个数. ...

  10. vs2010 配置OpenGL

    为了之后的项目学习,需要学习OpenGL.在此进行下记录,方便查询. 准备工作: 到https://www.opengl.org/resources/libraries/glut/glutdlls37 ...