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

Bookmark this website for more workarounds and issue fixes.

Verify Zip file contents without extracting using C# + Selenium

While doing automation testing, we may get a scenario where we need to download a zip file and to validate the contents inside it. One way t...