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

相关推荐
尼罗河女娲1 分钟前
【获取WebSocket】使用 Playwright 监听 Selenium 自动化测试中的 WebSocket 消息(二)
websocket·网络协议·selenium
了一梨7 分钟前
网络编程:UDP Socket
linux·网络协议·udp
云和数据.ChenGuang18 分钟前
F5 Big-IP by SNMP.硬件负载均衡
网络协议·tcp/ip·负载均衡·数据库运维工程师·运维教程
2501_9160088925 分钟前
iOS 应用发布流程中常被忽视的关键环节
android·ios·小程序·https·uni-app·iphone·webview
BuffaloBit29 分钟前
5G为何强调“NR”?
网络协议·5g
HyperAI超神经31 分钟前
【TVM 教程】交叉编译与 RPC
网络·人工智能·网络协议·rpc·gpu·编程语言·tvm
qq_4480111611 小时前
python HTTP请求同时返回为JSON的异常处理
python·http·json
老蒋新思维14 小时前
创客匠人:认知即资产 ——AI 时代创始人 IP 知识变现的底层逻辑
网络·人工智能·网络协议·tcp/ip·重构·创始人ip·创客匠人
ZXF_H15 小时前
Linux tcpdump抓包实践(以http为例)
linux·http·wireshark·tcpdump
白驹过隙^^15 小时前
OB-USP-AGENT安装使用方法
数据库·经验分享·网络协议·tcp/ip·github·ssl