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

相关推荐
王二端茶倒水1 天前
从千兆到万兆:宽带运营不能只卖套餐,要管用户生命周期从千兆到万兆:宽带运营需要管理用户生命周期
后端·网络协议·架构
牛奶2 天前
HTTPS你不知道的事
前端·https·浏览器
extrao3 天前
🚀 Kea DHCP4 自动分配系统完整搭建
网络协议
喵个咪3 天前
Go-Wind HTTP 服务器从入门到精通
后端·http·go
不做菜鸟的网工5 天前
BGP特性
网络协议
AlfredZhao5 天前
生产环境里,为什么不建议把普通端口直接暴露到公网?
linux·https·443·80
明月_清风7 天前
开发者网络概念全扫盲:一篇搞定
后端·网络协议
刘马想放假7 天前
Modbus 全栈技术解析:TCP、RTU、ASCII、RTU over TCP
数据结构·网络协议
王二端茶倒水8 天前
一套可落地的无线运营方案,不能只管 AP,还要管用户、计费和运维
网络协议