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

相关推荐
我今晚不熬夜2 小时前
Java语言实现Modbus协议通过用串口读取数据(以RTU为例)
java·网络协议
DLYSB_6 小时前
《从零开始搭建机房轻量化“声光告警”系统:基于 HTTP API 与 TTS 的运维实践》
运维·网络协议·http·报警灯
ZhengEnCi7 小时前
N3A-一个端口只能给一个程序使用吗?
网络协议
发光的沙子7 小时前
FPGA----配置根文件系统ip和mac地址
网络协议·tcp/ip·macos
2501_915909068 小时前
IPA 深度混淆是什么意思?从混淆强度到实际效果的解读
android·ios·小程序·https·uni-app·iphone·webview
Arbori_262158 小时前
TCP 通信协议
网络·网络协议·tcp/ip
一棵树73519 小时前
跨域资源共享cors
http·cors
华清远见成都中心1 天前
物联网通信协议对比:MQTT、CoAP、HTTP到底该怎么选
物联网·网络协议·http
kk的vmware虚拟机安装ubuntu1 天前
鱼皮 yu-rpc:从 0 到 1 手写 RPC 框架的实践教程
网络·网络协议·其他·rpc
耍酷的魔镜1 天前
谈谈如何使用Netty开发实现高性能的RPC服务器
服务器·网络协议·rpc