Android异常:java.lang.IllegalStateException: Unable to extract the trust manager on Android10Platform, sslSocketFactory is class com.android.org.conscrypt.OpenSSLSocketFactoryImpl
web、java项目异常:javax.net.ssl. SSLHandshakeException:PKIX path building failed
以下解决,第一步创建NullHostNameVerifier
package com.malx.signature.network;
import android.annotation.SuppressLint;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSession;
/**
* @author by maliang on 2021/12/13 17:25
* #First Created Time:
* #包名:com.malx.signature
* class description:用于主机名验证,此不校验允许所有。
*/
public class NullHostNameVerifier implements HostnameVerifier {
/**
* Verify that the host name is an acceptable match with
* the server's authentication scheme.
*
* @param hostname the host name
* @param session SSLSession used on the connection to host
* @return true if the host name is acceptable
*/
@SuppressLint("BadHostnameVerifier")
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
}
第二步 :
创建OkHttpClient示例(中间其他配置代码省略...):
import java.net.Proxy;
import java.security.K

本文档介绍了一种解决Android10平台上出现的`java.lang.IllegalStateException:Unabletoextractthetrustmanager`异常的方法,以及处理Java项目中`javax.net.ssl.SSLHandshakeException:PKIXpathbuildingfailed`异常的方案。通过创建自定义的`NullHostNameVerifier`和不受信任的`X509TrustManager`,允许应用程序忽略SSL证书验证,从而在不安全的网络环境中进行通信。同时,代码示例展示了如何在OkHttpClient中应用这些解决方案,以实现不受限制的主机名验证和SSL握手。
712

被折叠的 条评论
为什么被折叠?



