Skip to content

Instantly share code, notes, and snippets.

@fastnsilver
Created March 12, 2015 04:19
Show Gist options
  • Save fastnsilver/4af20978e8994ea1463e to your computer and use it in GitHub Desktop.
Save fastnsilver/4af20978e8994ea1463e to your computer and use it in GitHub Desktop.
Obtain Self Signed Cert
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);
}
}
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