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

相关推荐
小米里的大麦3 小时前
050 传输层 —— UDP
网络·网络协议·udp
陌路206 小时前
Linux35 TCP状态转换图
网络·网络协议·tcp/ip
k***3886 小时前
Node.js HTTP模块详解:创建服务器、响应请求与客户端请求
服务器·http·node.js
00后程序员张8 小时前
接口调试从入门到精通,Fiddler抓包工具、代理配置与HTTPS抓包实战技巧
前端·ios·小程序·https·fiddler·uni-app·webview
i***48618 小时前
Nginx中$http_host、$host、$proxy_host的区别
运维·nginx·http
不一样的故事12611 小时前
将 Git 远程仓库的地址从 HTTP 修改为 SSH,
git·http·ssh
j***485415 小时前
Node.js实现WebSocket教程
websocket·网络协议·node.js
青果网络_xz15 小时前
全球代理IP是什么?它和普通代理有什么区别?
网络·网络协议·tcp/ip
长城202416 小时前
HTTP头信息相关知识了解
http·http头信息·http头字段·头信息·头子段