OkHttpClient client = new OkHttpClient.Builder()
.sslSocketFactory(getSSLContext().getSocketFactory(), new AllTrustManager())
.build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Config.BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
/*.client(client)*/
.build();
private SSLContext getSSLContext(){
SSLContext sslContext = null;
try {
sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, new TrustManager[]{new AllTrustManager()}, new SecureRandom());
} catch (Exception e) {
e.printStackTrace();
}
return sslContext;
}
private class AllTrustManager implements X509TrustManager {
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
}
网友评论