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

相关推荐
GanGuaGua10 分钟前
计算机网络:HTTP报文
网络·网络协议·计算机网络·http
发光小北26 分钟前
SG-TCP232-620(六通道串口服务器)特点与功能介绍
网络协议
00后程序员张1 小时前
fastlane 结合 appuploader 命令行实现跨平台上传发布 iOS App
android·ios·小程序·https·uni-app·iphone·webview
YY&DS1 小时前
《Qt 手写 HTTP 登录服务实战》
开发语言·qt·http
默凉1 小时前
c++使用http发送图像
开发语言·c++·http
老蒋新思维1 小时前
创客匠人观察:知识IP的下一站——与AI智能体共生的“人机协同”模式
大数据·人工智能·网络协议·tcp/ip·重构·创始人ip·创客匠人
游戏开发爱好者81 小时前
App Store 上架流程,结合多工具协作
android·ios·小程序·https·uni-app·iphone·webview
Gavin在路上2 小时前
dubbo源码之一次RPC请求的生死之旅(基于Dubbo 2.7.8)
网络协议·rpc·dubbo
科技块儿12 小时前
如何使用IP数据云提升网络风控、减少业务欺诈
网络·网络协议·tcp/ip
Sleepy MargulisItG13 小时前
【Linux网络编程】应用层协议:HTTP协议
linux·服务器·网络·http