November 10, 2019

Disable SSL verification while using HttpsURLConnection - Java

  November 10, 2019
If your website is not SSL secured, you can use below coded before sending a HTTP request to URL to bypass connection issue

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 public void DisableSSLChecking() 
 {
  TrustManager[] trustAllCerts = new TrustManager[]{
       new X509TrustManager() {
           public java.security.cert.X509Certificate[] getAcceptedIssuers() {
               return null;
           }
           public void checkClientTrusted(
               java.security.cert.X509Certificate[] certs, String authType) {
           }
           public void checkServerTrusted(
               java.security.cert.X509Certificate[] certs, String authType) {
           }
       }
   };

   // Install the all-trusting trust manager
   try {
       SSLContext sc = SSLContext.getInstance("SSL");
       sc.init(null, trustAllCerts, new java.security.SecureRandom());
       HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
   } catch (Exception e) {
    
   }
 }
logoblog

Thanks for reading Disable SSL verification while using HttpsURLConnection - Java

Previous
« Prev Post
Oldest
You are reading the latest post

No comments:

Post a Comment

How to send email from current Outlook instance using Java + VBScript

If we are using .Net, we can easily access outlook and send emails using its own libraries. But what if we are using Java? Here we can seek ...