当前位置: 首页 > article >正文

android https 证书过期

有的时候 我们android https 证书过期 ,或者使用明文等方式去访问服务器 可能会碰到类似的 问题 :

javax.net.ssl.SSLHandshakeException: Chain validation failed

java.security.cert.CertPathValidatorException: Response is unreliable: its validity interval is out-of-date

java.security.cert.CertPathValidatorException: Could not determine revocation status

所以我们 尝试使用一下方式解决 :

1) 忽略证书验证

TrustManager[] trustAllCerts = new TrustManager[] {
    new X509TrustManager() {
        public void checkClientTrusted(X509Certificate[] chain, String authType) {}
        public void checkServerTrusted(X509Certificate[] chain, String authType) {}
        public X509Certificate[] getAcceptedIssuers() {
            return new X509Certificate[0];
        }
    }
};

try {

   

HttpsURLConnection httpsURLConnection = (HttpsURLConnection) new URL("https://www.baidu.com").openConnection();

   SSLContext sslContext = SSLContext.getInstance("TLS");
   sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
   httpsURLConnection .setSSLSocketFactory(sslContext.getSocketFactory());

  httpsURLConnection .setHostnameVerifier((hostname, session) -> true);

......

   
} catch (Exception e) {
    e.printStackTrace();
}

如果您希望允许整个应用程序使用不安全的 HTTP 连接,可以在应用程序的清单文件(AndroidManifest.xml)中添加以下标记:

 

<application

android:usesCleartextTraffic="true" ...>

...

</application>

更详细的可以去问 gpt


http://www.kler.cn/a/157947.html

相关文章:

  • 机器学习笔记 - 基于深度学习计算视频中演员的出镜时间
  • Java异常详解大全(2023版)
  • android高版本适配使用Tools.java
  • CSS-200个小案例(一)
  • 优雅草蜻蜓I即时通讯·水银版私有化部署之java服务端搭建教程-01
  • [HTML]Web前端开发技术6(HTML5、CSS3、JavaScript )DIV与SPAN,盒模型,Overflow——喵喵画网页
  • 4、单例模式(Singleton Pattern)
  • 【开源视频联动物联网平台】写一个物联网项目捐献给Dromara组织
  • mysql时间类型处理
  • C++:文件操作
  • Jupyter Notebook中设置Cell主题
  • Java---异常
  • 人工智能-机器翻译:技术发展与代码实战
  • 机器学习实验二:决策树模型
  • react学习--Redux的使用
  • ios上传图片旋转问题解决方案(vant上传图片)
  • cmd下查看python命令的用法
  • Linux CenTOS命令备忘
  • java每日一记 —— BeanFactory 与 ApplicationContext 的区别
  • QT中如何使用自定义控件