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

相关推荐
卓码软件测评4 小时前
第三方软件质量检测:RTSP协议和HLS协议哪个更好用来做视频站?
网络·网络协议·http·音视频·web
川石课堂软件测试4 小时前
自动化测试之 Cucumber 工具
数据库·功能测试·网络协议·测试工具·mysql·单元测试·prometheus
卓码软件测评5 小时前
第三方媒体流压力测试:k6插件xk6-webrtc的使用来测试媒体流的性能
网络协议·测试工具·http·https·webrtc·ssl·媒体
悟能不能悟5 小时前
电脑没法ping通某个网段的ip
网络协议·tcp/ip·电脑
唐古乌梁海6 小时前
WebSocket vs HTTP 对比
websocket·http
duration~6 小时前
UDP 首部
网络·网络协议·udp
周杰伦_Jay7 小时前
【计算机网络三层深度解析:应用层、传输层与网络层】HTTP、TCP、UDP、IP、ICMP、ARP
tcp/ip·计算机网络·http
00后程序员张8 小时前
Swoole HTTPS 实战,在生产环境部署、性能权衡与排查流程
后端·ios·小程序·https·uni-app·iphone·swoole
一品威客网8 小时前
影视 IP 全链开发:App 如何成为核心
网络·网络协议·tcp/ip
AirDroid_cn10 小时前
Win11 远程桌面:连接公司电脑时,提示 “证书错误” 如何解决?
windows·网络协议·https·ssl·电脑技巧