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

相关推荐
牛马工作号12 小时前
Wi‑Fi 完全指南:从 802.11 协议到 Wi‑Fi 7、AC+AP 与 Mesh 工程组网
网络·网络协议·智能路由器
Geek-Chow12 小时前
ALB SSL policy conflict (AWS Load Balancer Controller)
网络协议·ssl·aws
爱刷碗的苏泓舒12 小时前
FTP、FTPS 与 WinSCP:原理、连接机制及 GNSS 工程应用
网络协议·ftp·winscp·数据下载·ftps
雲帝13 小时前
Windows虚拟机UDP大包分片排障
windows·网络协议·udp
ControlRookie13 小时前
第04篇_把 HTTP 放进 PLC:扫描周期、缓冲区、状态机和能力边界
http·codesys·plc通信
八代臻14 小时前
蒲公英免费异地组网
网络协议
記億揺晃着的那天14 小时前
HTTPS 页面内网直连 NAS:解决 Mixed Content 与公网带宽瓶颈
网络协议·http·https·nas
難釋懷16 小时前
Nginx代理https请求
redis·nginx·https
想学好C++的oMen17 小时前
socket编程TCP
linux·网络·网络协议·tcp/ip
GitLqr1 天前
别再盲目复制了:彻底搞懂 CORS 的本质与那些“神坑”
安全·http·面试