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

相关推荐
半壶清水29 分钟前
[软考网规考点笔记]-操作系统核心知识及历年真题解析
网络·网络协议·算法
方芯半导体2 小时前
EtherCAT “通信 + 控制“ 的全国产化控制方案,ESC芯片(FCE1323)与国产MCU芯片功能板解析
xml·网络·单片机·嵌入式硬件·网络协议·机器人·自动化
Zach_yuan3 小时前
UDP网络编程:从入门到精通
linux·网络·网络协议·udp
B2_Proxy3 小时前
破解TikTok运营困境:静态住宅IP与封号限流深度解析
网络·网络协议·tcp/ip
文章永久免费只为良心4 小时前
一站式综合查询工具:IP、企业信息与网络空间资产高效查询工具
网络·网络协议·tcp/ip
麻辣长颈鹿Sir5 小时前
TCP/IP四层架构通俗理解及功能介绍
网络协议·tcp/ip·tcp/ip协议四层架构·网络通信介绍
yanlou2336 小时前
[C++/Linux HTTP项目] HTTP服务器基于muduo高性能服务器搭载【深入详解】
运维·服务器·http·muduo库·http高性能服务器
2501_915918416 小时前
HTTPS 代理失效,启用双向认证(mTLS)的 iOS 应用网络怎么抓包调试
android·网络·ios·小程序·https·uni-app·iphone
北京耐用通信6 小时前
极简部署,稳定通信:耐达讯自动化Profibus光纤链路模块赋能物流自动化喷码效率提升
人工智能·物联网·网络协议·自动化·信息与通信
..过云雨7 小时前
从寻址到转发:网络层 IP 协议全流程工作原理详解
网络·网络协议·tcp/ip