报错:clientBuilder.sslSocketFactory(SSLSocketFactory) not supported on JDK 9+
原因是单参数的 构造函数 被弃用。
try {TrustManagerFactory trustManagerFactory = null;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));}X509TrustManager trustManager = (X509TrustManager) trustManagers[0];SSLContext sslContext = SSLContext.getInstance("TLS");sslContext.init(null, new TrustManager[]{trustManager}, null);SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();OkHttpClient okHttpClient = new OkHttpClient.Builder().sslSocketFactory(sslSocketFactory, trustManager).build()}catch(Exception e){}