Skip to content

Instantly share code, notes, and snippets.

@leolin310148
Created July 18, 2017 08:41
Show Gist options
  • Save leolin310148/f20f73c254bb61c9e9909e71493cd0c2 to your computer and use it in GitHub Desktop.
Save leolin310148/f20f73c254bb61c9e9909e71493cd0c2 to your computer and use it in GitHub Desktop.
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