如果是单个的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. oracle数据操纵语言(DML)data manipulation language

    数据库操纵语言(DML)用于查询和操纵模式对象中的数据,它不隐式地提交当前事务. SELECTINSERTUPDATEDELETECALLEXPLAIN PLANLOCK TABLEMERGE使用算术 ...

  2. first集合及follow集合

    前面那片文章生成的语法分析表并不是最优的,因为有些项在遇到错误输入的时候,并不是采取报错,而是执行规约,直到不能再规约的时候才报错.这是不科学的,我们需要在得到错误输入的时候立马报错,为了实现这个功能 ...

  3. poj 3621 0/1分数规划求最优比率生成环

    思路:以val[u]-ans*edge[i].len最为边权,判断是否有正环存在,若有,那么就是ans小了.否则就是大了. 在spfa判环时,先将所有点进队列. #include<iostrea ...

  4. ios卡牌游戏项目源码

    上传者fu_sion,源码CardGame,一副牌从中抽取十二张牌,翻开牌可以相同的花色+1 相同的数字+4分 同一张牌翻开后可以盖上(算是一个BUG)就酱紫~~ 项目源码下载:http://code ...

  5. 上传至应用商店以及testflight相关。

    对于一个新的开发者账号来说,首先你需要创建一个新的发布证书.这个证书只要创建一次就行了,如果以后用的话,直接拿过来用就行了,当然发布证书是和配置文件一起使用的,还有就是关于p12,就是用创建证书的电脑 ...

  6. 关联表映射 Association Table Mapping

    把关联保存为一个表,存储关联表的外键 在对象中,使用集合作为域值,来处理多值域. 而在DB中,只能有单值域. 外键映射的核心,是在关联关系的单值端使用外键来维持联系. 而在多对多的关联关系中,已经不存 ...

  7. 《JavaScript高级程序设计》心得笔记-----第一篇章

    第一章 JavaScript由ECMAScript.DOM.BOM组成.其中BOM功能在HTML5中有了正式的规范,使BOM的兼容性越来越高. 第二章 1.<script>属性中的asyn ...

  8. 济南学习 Day1 T3 am

    凝视[问题描述]背包是个好东西,希望我也有.给你一个二维的背包,它的体积是N*M.现在你有一些大小为1× 2和1×3的物品,每个物品有自己的价值.你希望往背包里面装一些物品,使得它们的价值和最大,问最 ...

  9. LLVM language 参考手册(译)(6)

    模块级内联汇编(Module-Level Inline Assembly) 模块包含“module-level inline assembly”块,这与GCC中的“file scope inline ...

  10. webstorm 添加文件模板

    Ctrl+Shift+A 搜索设置 File Teamplate ​ 添加 File Teamplate