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

相关推荐
落叶_Jim10 小时前
2026年Nginx配置HTTPS全流程-从零到自动续期实战指南
运维·nginx·https
Arman_11 小时前
02 rusty-cat 实战:MeowClient 配置、任务参数、进度回调与暂停恢复
http·https·rust·tokio·文件分片上传·文件分片下载
汤愈韬13 小时前
hcip-security_防火墙高可靠技术3_防火墙链路高可靠技术
网络·网络协议·网络安全
liulilittle14 小时前
TCP UCP v1.0:当 BBRv1 遇上卡尔曼滤波
网络·网络协议·tcp/ip
wangjialelele15 小时前
HTTP Cookie 和 Session
http·cookie·session
小娄~~15 小时前
TCP/IP协议和TFTP协议
网络·网络协议·tcp/ip
xiaoxue..15 小时前
HTTPS:更安全的HTTP,从加密原理、数字证书到TLS 握手全解析
网络协议·面试·https
liulilittle16 小时前
TCP UCP v1.0 拥塞控制算法(Linux Kernel CC-A)
linux·网络·网络协议·tcp/ip·c·通信·拥塞控制
仍然.17 小时前
传输层协议UDP
网络·网络协议·udp
艾莉丝努力练剑17 小时前
【Linux网络】Linux 网络编程:HTTP(一)协议初识
linux·运维·服务器·网络·tcp/ip·计算机网络·http