Created
March 12, 2015 04:19
-
-
Save fastnsilver/4af20978e8994ea1463e to your computer and use it in GitHub Desktop.
Obtain Self Signed Cert
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
private static SSLContext obtainTrustSelfSignedSSL() { | |
TrustManager[] trustAllCerts = new TrustManager[]{ | |
new X509TrustManager() { | |
@Override | |
public java.security.cert.X509Certificate[] getAcceptedIssuers() { | |
return null; | |
} | |
@Override | |
public void checkClientTrusted(java.security.cert.X509Certificate[] arg0, String arg1) | |
throws CertificateException { | |
} | |
@Override | |
public void checkServerTrusted(java.security.cert.X509Certificate[] arg0, String arg1) | |
throws CertificateException { | |
} | |
}}; | |
try { | |
SSLContext sc = SSLContext.getInstance("SSL"); | |
sc.init(null, trustAllCerts, new java.security.SecureRandom()); | |
return sc; | |
} catch (Exception e) { | |
e.printStackTrace(); | |
throw new RuntimeException(e); | |
} | |
} |
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
HttpPost post = new HttpPost(PanelServiceConfig.url); | |
// some work to create post request | |
httpClient = HttpClientBuilder.create().setSslcontext(obtainTrustSelfSignedSSL()).build(); | |
HttpResponse response = httpClient.execute(post); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment