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

相关推荐
国服第二切图仔3 小时前
检测隧道HTTP代理的可用性的几种方法
网络·网络协议·http
托尼吴3 小时前
REST RPC dubbo,HSF 协议总结
网络协议·rpc·dubbo
JH30733 小时前
引依赖包和对这个包发起rpc调用有什么区别
网络·网络协议·rpc
2501_916008894 小时前
API接口调试全攻略 Fiddler抓包工具、HTTPS配置与代理设置实战指南
前端·ios·小程序·https·fiddler·uni-app·webview
程序员小单4 小时前
WebSocket 与 Spring Boot 整合实践
spring boot·websocket·网络协议
游戏开发爱好者88 小时前
Mac 抓包软件怎么选?从 HTTPS 调试、TCP 数据流分析到多工具协同的完整抓包方案
tcp/ip·macos·ios·小程序·https·uni-app·iphone
海域云-罗鹏9 小时前
电商掘金日本:SDWAN专线刚需原因
服务器·网络·网络协议
翻斗花园正门保安小夏9 小时前
HTTPS + WSS(WebSockets) 完整请求流程架构说明及本地开启HTTPS
websocket·网络协议·https
2501_9159184110 小时前
苹果上架 iOS 应用的工程实践,一次从零到上线的完整记录
android·ios·小程序·https·uni-app·iphone·webview
发光小北11 小时前
SG-TCP-Profibus (M)(ModbusTCP 转 Profibus DP 网关)
网络·网络协议·tcp/ip