当前位置: 首页 > article >正文

sslSocketFactory not supported on JDK 9+

clientBuilder.sslSocketFactory(SSLSocketFactory) not supported on JDK 9+
at okhttp3.internal.platform.Jdk9Platform.trustManager(Jdk9Platform.kt:61)
at okhttp3.OkHttpClient$Builder.sslSocketFactory(OkHttpClient.kt:751)
at

1.升版本4.9.3以上

2、加个函数获取X509TrustManager

public static X509TrustManager getX509TrustManager() {
        X509TrustManager trustManager = null;
        try {
            TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
            trustManagerFactory.init((KeyStore) null);
            TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
            if (trustManagers.length != 1 || !(trustManagers[0] instanceof X509TrustManager)) {
                throw new IllegalStateException("Unexpected default trust managers:" + Arrays.toString(trustManagers));
            }
            trustManager = (X509TrustManager) trustManagers[0];
        } catch (Exception e) {
            e.printStackTrace();
        }

        return trustManager;
    }

3.创建的时候加上上面的X509TrustManager

 private static synchronized OkHttpClient getInstance() {
        okHttpClient = new OkHttpClient().newBuilder()
                .connectTimeout(15, TimeUnit.SECONDS)
                .readTimeout(15, TimeUnit.SECONDS)
                .writeTimeout(15, TimeUnit.SECONDS)
                .sslSocketFactory(new SSLSocketClient().getSSLSocketFactory(),SSLSocketClient.getX509TrustManager())//配置
                .hostnameVerifier(new SSLSocketClient().getHostnameVerifier())//配置
                .build();
        if (okHttpClient == null) {
            okHttpClient = new OkHttpClient();
        }
        return okHttpClient;
    }

重点是下面这句

.sslSocketFactory(new SSLSocketClient().getSSLSocketFactory(),SSLSocketClient.getX509TrustManager())

参考链接:使用okhttp3,提示【clientBuilder.sslSocketFactory(SSLSocketFactory) not supported on JDK 9+】


http://www.kler.cn/a/395829.html

相关文章:

  • 《FreeRTOS任务控制块篇》
  • 数据结构小项目
  • SHA-256哈希函数
  • 使用API有效率地管理Dynadot域名,编辑账户中whois联系人信息
  • UniApp 应用、页面与组件的生命周期详解
  • AI制作ppt
  • [前端面试]HTML AND CSS
  • Android OpenGL ES详解——实例化
  • stm32教程:OLED屏显示字母、汉字、图片工程讲解
  • 第1章: 初识Pillow(PIL)
  • Docker 容器常见故障排查及处理
  • 学习用 Javascript、HTML、CSS 以及 Node.js 开发一个 uTools 插件,学习计划及其周期
  • 游戏引擎学习第12天
  • 掌握Electron工具链:在Windows操作系统上无缝开发MacOS软件
  • 浅谈React的虚拟DOM
  • Apache Paimon、Apache Hudi、Apache Iceberg对比分析
  • Spring Cloud Vault快速入门Demo
  • C++ 错题本 MAC环境下 unique_lock try_lock_for函数爆红问题
  • emp.dll文件丢失的几种方法-常见问题
  • Java之JDBC,Maven,MYBatis
  • Java多线程八股(一), 锁策略,synchronized锁策略详解
  • Tiktok对接和内容发布申请流程
  • sql专场练习(二)(1-5)
  • 【智能化仪表设计】化工仪表及自动化全套课件
  • Java进阶 - AOP
  • 无人机:科技改变生活的神奇力量