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

相关推荐
_OP_CHEN14 分钟前
【从零开始的Qt开发指南】(二十一)Qt 网络编程封神指南:UDP/TCP/HTTP 全场景实战
网络·qt·http·udp·tcp·前端开发·qt网络
小码吃趴菜16 分钟前
UDP知识点总结
网络协议·tcp/ip·udp
程序员zgh18 分钟前
汽车以太网协议 —— DDS
c语言·开发语言·c++·网络协议·udp·汽车·信息与通信
不一样的故事12611 小时前
下的 “Wi-Fi参数配置” 列表,但您当前选中的导航菜单项是 “IP规划”。您遇到的 “IP加载不出来” 问题,很可能
网络协议·tcp/ip·华为
枷锁—sha16 小时前
彻底解决 Google Gemini 报错:异常流量与 IP 地址冲突排查指南
网络·网络协议·tcp/ip
逐梦苍穹17 小时前
不用公网 IP,把内网服务安全发布到公网:ZeroNews 快速上手
网络协议·tcp/ip·安全·内网穿透
好多渔鱼好多18 小时前
【流媒体协议】RTSP / RTP / RTCP 协议全景介绍
网络·网络协议·rtp·rtsp·rtcp·ipc摄像头
蜂蜜黄油呀土豆19 小时前
计算机网络中的传输层:深入解析 TCP 协议
网络协议·tcp/ip·计算机网络·三次握手·网络排查
2501_9159184119 小时前
除了 Perfdog,如何在 Windows 环境中完成 iOS App 的性能测试工作
android·ios·小程序·https·uni-app·iphone·webview
五仁火烧20 小时前
HTTP 服务器
服务器·网络·网络协议·http