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 X509Certificate0;

}

}

};

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

相关推荐
sweet丶12 小时前
MQTT消息通道-基础篇
网络协议
奥利奥夹心脆芙14 小时前
辅助排查 HTTP 接口代码报错,实操完整案例分享
http
吠品14 小时前
一次 Nginx 报错 unexpected end of file 的排查记录
网络协议·https·ssl
代码中介商14 小时前
TLS握手全解析:从1.2到1.3的加密演进
网络·网络协议·http
xlq2232215 小时前
66.ip
网络·网络协议·tcp/ip
华纳云IDC服务商15 小时前
高防CDN和高防IP一起用,延迟会增加多少?
网络·网络协议·tcp/ip
yuegu77716 小时前
HarmonyOS应用<节气通>开发第25篇:HTTP请求封装
网络协议·http·harmonyos
IT大白鼠16 小时前
BGP多归属技术原理与应用实践
网络·网络协议·华为
忧云17 小时前
HTTP抓包工具:安装配置与使用教程
网络协议·网络抓包工具·http抓包
00后程序员张17 小时前
Jenkins 自动上传 IPA 到 App Store 把发布步骤融入 CI/CD
android·ios·小程序·https·uni-app·iphone·webview