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

相关推荐
meilindehuzi_a29 分钟前
React JWT 登录鉴权实战:从无状态 HTTP 到路由守卫、Zustand 与 Axios 拦截器
前端·react.js·http
Amir_zy43 分钟前
TCP/IP 与 WebSocket 测试实战:从底层原理到场景落地
websocket·网络协议·tcp/ip
00后程序员张1 小时前
Windows / Linux / Mac 上不用 Xcode 把 IPA 上传到 App Store,upload 命令详解
android·ios·小程序·https·uni-app·iphone·webview
eggrall2 小时前
Socket编程UDP
网络协议·udp·php
bitbrowser19 小时前
MXToolbox检测IP只红一个黑名单时,如何判断?
网络·网络协议·tcp/ip
智购科技自动贩卖机1 天前
自动售货机硬件主控方案选型实战:单片机、树莓派、ESP32怎么选?
人工智能·单片机·嵌入式硬件·物联网·网络协议·yolo·架构
凤山老林1 天前
从 RestTemplate 到 HttpClient 5:Spring Boot HTTP 客户端性能调优与连接池治理
spring boot·后端·http
00后程序员张1 天前
SSL Pinning 抓包抓不到明文?绕过证书固定的几种方案
网络协议·计算机网络·网络安全·ios·adb·https·udp
微硬创新1 天前
不用换设备,也能接入智能系统:耐达讯自动化NY-B801网关的神奇功效
人工智能·网络协议·自动化·信息与通信
2301_777998341 天前
Linux网络:UDP 网络编程
linux·网络·网络协议·udp