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 小时前
【筑基·055】TCP vs UDP:可靠和快速的取舍
网络协议·tcpdump
小此方5 小时前
Linux网络(十二):HTTP短连接与长连接:从Connection机制到Cookie、Session,彻底理解HTTP的无状态
服务器·网络·http
江畔柳前堤6 小时前
On-Policy Distillation 全景深潜
人工智能·网络协议·目标检测·http·机器学习·chatgpt·重构
2501_915909068 小时前
怎么用 FlutterFlow 把应用发布到 App Store?
android·ios·小程序·https·uni-app·iphone·webview
1570925113418 小时前
Android进阶之光:HTTP协议原理深度解析
android·网络协议·http
可爱系程序猿1 天前
WSD 打印机时好时坏:从发现服务、地址变化到 Standard TCP/IP 端口的迁移记录
网络·网络协议·tcp/ip·程序人生·电脑
2501_916008891 天前
全平台抓包工具,Windows、iPhone、Linux三个平台抓包测试
网络协议·计算机网络·网络安全·ios·adb·https·udp
szephyr1 天前
Nginx 反向代理实战:从 502、跨域到 HTTPS,一次打通
运维·nginx·https·部署·反向代理
努力的lpp1 天前
【攻击溯源四步法 · 面试讲解稿】
网络·网络协议·安全
cccc卌1 天前
HTTP协议总结
网络·网络协议·http