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

相关推荐
basketball6168 小时前
HTTP协议返回状态码总结
网络·网络协议·http
茉莉清茶LG9 小时前
虚拟机NAT模式下,无法直接在主机通过IP网址打开界面
网络·网络协议·tcp/ip
雪的季节9 小时前
DDS通信支持UDP与TCP
网络协议·tcp/ip·udp
network_tester12 小时前
TSN网络流量及协议测试:为确定性网络护航的关键技术
网络·网络协议·车载系统·汽车·信息与通信·信号处理
是Yu欸12 小时前
CC-Switch 零基础保姆级教程1(2026 最新版)
网络·人工智能·网络协议·http·大模型·claude·claude desktop
夏天测13 小时前
【高危漏洞通告】NGINX ngx_http_rewrite_module 堆缓冲区溢出漏洞;详解与修复方案
运维·nginx·http
FallenQu13 小时前
【漏洞】CVE-2026-42945:NGINX ngx_http_rewrite_module 堆缓冲区溢出深度分析
运维·nginx·http
黄毛火烧雪下13 小时前
Mac 上用 Charles 抓取 iPhone 的 HTTPS 请求
网络协议·macos·https
阿拉金alakin15 小时前
UDP 报文结构与核心注意事项总结
网络·网络协议·udp·java-ee
Ether IC Verifier16 小时前
TCP 状态机详解
网络·网络协议·tcp/ip·计算机网络