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 {

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

相关推荐
yi碗汤园22 分钟前
【超详细】TCP编程与UDP编程
网络·网络协议·tcp/ip·unity·udp·visual studio
Ankie Wan25 分钟前
SOME/IP: Scalable service-Oriented MiddlewarE over IP车载以太网的服务化通信协议
网络协议·tcp/ip·ecu·can总线·some/ip·autostar
海棠蚀omo40 分钟前
从初识到深入:一次完整的 HTTP 协议系统性理解之旅
网络·网络协议·http
小霸王_3003786340 分钟前
《Google 与 Edge 浏览器对HTTP到HTTPS重定向处理的差异》
http·google·https·edge
嵌入式学习菌1 小时前
含谐波的功率因数问题
物联网·http
北京盟通科技官方账号1 小时前
Docker 容器化部署 EtherNet/IP 协议栈(ESDK):Windows 与国产银河麒麟 V10 实测对比
网络·网络协议·tcp/ip·docker·国产系统·ethernet/ip·工业协议
举手1 小时前
UDP Echo Server(学习版)
linux·服务器·网络·网络协议·学习·udp
蜂蜜黄油呀土豆1 小时前
深入解析计算机网络中的应用层知识:HTTP 与 HTTPS
网络协议·计算机网络·http·https·ssl/tls
weixin_462446231 小时前
Ubuntu 使用 systemd + Nginx 部署 code-server(含 HTTPS)
nginx·ubuntu·https