Created
July 18, 2017 08:41
-
-
Save leolin310148/f20f73c254bb61c9e9909e71493cd0c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static { | |
HttpsURLConnection.setDefaultHostnameVerifier((s, sslSession) -> true); | |
TrustManager[] trustManagers = new TrustManager[]{ | |
new X509TrustManager() { | |
@Override | |
public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { | |
} | |
@Override | |
public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { | |
} | |
@Override | |
public X509Certificate[] getAcceptedIssuers() { | |
return new X509Certificate[0]; | |
} | |
} | |
}; | |
try { | |
SSLContext sc = SSLContext.getInstance("TLS"); | |
sc.init(null, trustManagers, new SecureRandom()); | |
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); | |
} catch (Exception e) { | |
throw new RuntimeException(e); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment