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

相关推荐
御控工业物联网9 分钟前
御控网关如何实现MQTT、MODBUS、OPCUA、SQL、HTTP之间协议转换
数据库·sql·http
en-route1 小时前
HTTP cookie
网络·网络协议·http
yqcoder1 小时前
2. 你可以说一下 http 版本的发展过程吗
网络·网络协议·http
诗句藏于尽头10 小时前
完成ssl不安全警告
网络协议·安全·ssl
会飞的鱼先生13 小时前
Node.js-http模块
网络协议·http·node.js
-qOVOp-17 小时前
408第三季part2 - 计算机网络 - ip分布首部格式与分片
网络协议·tcp/ip·计算机网络
数通Dinner18 小时前
RSTP 拓扑收敛机制
网络·网络协议·tcp/ip·算法·信息与通信
G等你下课1 天前
AJAX请求跨域问题
前端·javascript·http
qq_171538851 天前
TCP/IP协议精解:IP协议——互联网世界的邮政编码系统
网络·网络协议·tcp/ip
兮动人1 天前
获取终端外网IP地址
java·网络·网络协议·tcp/ip·获取终端外网ip地址