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

Fixing javascript error: Cannot read properties of null (reading 'querySelector') issue when using CSS identifier in selenium

 JavaScript is another way to interact with web elements when normal selenium methods fail to act. But one issue with javascript is, it does...