设置可访问所有的https网站HttpsUtils.SSLParams sslParams = HttpsUtils.getSslSocketFactory(null, null, null);OkHttpClient okHttpClient = new OkHttpClient.Builder()//其他配置....sslSocketFactory(sslParams.sSLSocketFactory, sslParams.trustManager).build();OkHttpUtils.initClient(okHttpClient);设置具体的证书HttpsUtils.SSLParams sslParams = HttpsUtils.getSslSocketFactory(证书的inputstream, null, null);OkHttpClient okHttpClient = new OkHttpClient.Builder()//其他配置....sslSocketFactory(sslParams.sSLSocketFactory, sslParams.trustManager)).build();OkHttpUtils.initClient(okHttpClient);
如果还是有问题的话,建议在代码中其他配置处加上一句代码:
.hostnameVerifier(new HostnameVerifier() {@Overridepublic boolean verify(String hostname, SSLSession session) {return true;}})
OkhttpUtils的https请求 - 简书