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

相关推荐
Multipath7121 小时前
多链路聚合,让具身智能高频视觉感知数据 “回得来、来得快、不中断”
网络·网络协议·5g·智能路由器·信息与通信
重生之高冷汉堡包1 小时前
家庭住宅IP是什么?机房住宅与普通住宅有什么区别
运维·服务器·网络·网络协议·tcp/ip·用户运营
j7~2 小时前
【Linux网络加餐】《HTTPS 协议原理》---详解
网络·网络协议·https·加密·ca认证·解密
紧跟先前的步伐5 小时前
Go AI Agent 实战 12|HTTP 状态码、API 错误处理与日志
开发语言·人工智能·http·ai·golang
byte轻骑兵5 小时前
【HIDS】规范精讲[3]:把连接间隔压到极限——SCI 四档调速的底层机制
网络·网络协议·人机交互·hids·蓝牙协议
流浪0015 小时前
计算机网络篇7:传输层——TCP 网络编程常用接口与调用流程
网络协议·tcp/ip·计算机网络·listen·tcp接口
比兔代理6 小时前
静态 IP 的粘性会话原理,以及连接稳定性解析
网络·网络协议
Lsetea6 小时前
curl下载HTTPS正文是乱码:--compressed与Content-Encoding分层排查
linux·http·https·ssl证书·curl
刘胡子大叔7 小时前
curl resolve 和 Host 头的两种免 DNS 验证 HTTPS
网络协议·http·https
j7~7 小时前
【Linux网络加餐】《HTTP 会话保持:Cookie 与 Session 原理及实验验证》---详解
linux·网络·网络协议·http·cookie·session