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

相关推荐
mjr17 分钟前
基于Netty的WebSocket实时消息推送系统
网络·websocket·网络协议
菜鸟厚非39 分钟前
如何在 Nginx 中配置 HTTPS - Linux
linux·nginx·https
资深web全栈开发1 小时前
QUIC 协议:为什么谷歌要用 UDP 重做一遍 TCP?
网络协议·tcp/ip·udp
jiecy1 小时前
基础问题:1.1.1.2/24 和 1.1.1.2/22 是同一个 IP 吗?
网络·网络协议·tcp/ip
Anthony_2312 小时前
三、路由基础与静态路由
网络·网络协议·tcp/ip·http·udp·智能路由器
huohaiyu2 小时前
UDP协议
网络·网络协议·udp
一轮弯弯的明月2 小时前
TCP连接管理(三次握手与四次挥手)
网络·经验分享·笔记·网络协议·tcp/ip·学习心得
forestsea2 小时前
GitHub HTTPS 提交代码与个人访问令牌配置指南
网络协议·https·github
YYYing.3 小时前
【计算机网络 | 第十篇】计网之应用层(一)—— 万字解析应用层,一文带你搞懂HTTP、WWW、Cookie和Session
网络·网络协议·计算机网络·http
それども3 小时前
线程池阻塞队列选择ArrayBlockingQueue与LinkedBlockingQueue区别
java·开发语言·网络协议