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

相关推荐
00后程序员张1 分钟前
混合 App 怎么加密?分析混合架构下常见的安全风险
android·安全·小程序·https·uni-app·iphone·webview
曾几何时`1 分钟前
网络协议(五)数据链路层 ARP协议
网络·网络协议
玥轩_52117 分钟前
防火墙技术-综合应用实验
运维·网络·网络协议·网络安全·智能路由器·路由器·防火墙
最贪吃的虎21 分钟前
网络是怎么传输的:从底层协议到浏览器访问网站的全过程剖析
java·开发语言·网络·http·缓存
北京盟通科技官方账号26 分钟前
合规、安全与扩展:NetStaX新版本如何应对EtherNet/IP协议的技术挑战?
服务器·网络·网络协议·自动化·制造
RichardMiao1 小时前
axios 的 withCredentials 到底做了什么?
前端·javascript·http
Python私教2 小时前
鸿蒙应用的网络请求和数据处理:从HTTP到本地缓存的完整方案
网络·http·harmonyos
web Rookie2 小时前
一文分清 TCP、UDP、HTTP:网络协议核心区别
网络协议·tcp/ip·http·udp
Watermelo6172 小时前
【前端实战】Axios 错误处理的设计与进阶封装,实现网络层面的数据与状态解耦
前端·javascript·网络·vue.js·网络协议·性能优化·用户体验
chen_x_x3 小时前
域格模组使用http下载到文件系统以及分段下载
网络协议·http·xcode