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 X509Certificate0;

}

}

};

try {

SSLContext sslContext = SSLContext.getInstance("TLS");

sslContext.init(null, trustAllCerts, new java.security.SecureRandom());

HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());

// 进行网络请求...

} catch (Exception e) {

e.printStackTrace();

}

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

复制代码

<application

android:usesCleartextTraffic="true" ...>

...

</application>

更详细的可以去问 gpt

相关推荐
上海云盾-小余6 小时前
BGP 高防 IP 与 CDN 混合部署:攻防场景选型实战指南
网络·网络协议·tcp/ip
2501_916007478 小时前
前端开发常用软件与工具全面指南
android·ios·小程序·https·uni-app·iphone·webview
天天进步201511 小时前
Tunnelto 源码解析 #4:Wormhole 控制通道:WebSocket 如何建立一条“隧道控制线”
网络·websocket·网络协议
古道青阳13 小时前
深入密码学内核:对称/非对称原理、PKI体系及C语言实现
网络协议·https·ssl
2501_9159090613 小时前
iOS应用性能优化:十大策略提升用户体验与开发效率
android·ios·小程序·https·uni-app·iphone·webview
夜月yeyue15 小时前
KCP 与 UDP 可靠传输
linux·网络·单片机·网络协议·udp·php
WIZnet15 小时前
W55RP20-EVB-MKR MicroPython 实战(14):MQTT 协议与 OneNET 平台对接
单片机·网络协议·wiznet
GlobalSign数字证书16 小时前
中小企业的 SSL/TLS 证书管理,有更轻量的方案
数据库·网络协议·ssl
郑洁文16 小时前
基于Python的HTTP服务漏洞信息收集工具设计与实现
开发语言·python·http
熊出没19 小时前
我用 Netty TCP 搭建物联网云平台,并对接车辆电池信息解析
物联网·网络协议·tcp/ip