title: Tring to connect using HTTPS: Server redirected too many times
body: <p>I am trying to connect to a secured connection URL (https://example.com ) using a Java program to check availability of the site. Generally, I connect to <a href="https://example.com" rel="nofollow">https://example.com</a> in browser by disabling proxy settings. Also, we have installed certificates in trusted root certificates. 
  I have added these certificates to Java Keystore successfully.</p>
  
  <pre><code>  import java.net.URL;
      import java.net.URLConnection;
      import java.security.Security.*;
      import com.sun.net.ssl.*;
      import com.sun.*; 
  
      import javax.net.ssl.HttpsURLConnection;
      import java.security.cert.Certificate;
      import java.io.*;
      import javax.net.ssl.SSLPeerUnverifiedException;
      import org.omg.CORBA_2_3.portable.InputStream;
  
      public class TestConn {
      public static void main(String args [])
      {
          try{
                   URL hp = new URL("https://example.com");
                  HttpsURLConnection hpCon = (HttpsURLConnection)hp.openConnection();
  
          boolean isProxy = hpCon.usingProxy();
          System.out.println("is using proxy " + isProxy);
          InputStream obj = (InputStream) hpCon.getInputStream();
          while(obj.read()!=-1){
              System.out.println(obj.read_char());
  
          }
                  System.out.println("content &gt;&gt; " + obj.toString());
          }catch (Exception ex){
              ex.printStackTrace();
          }
      }
      }
  </code></pre>
  
  <p>I have encountered the following error:</p>
  
  <pre><code>java.net.ProtocolException: Server redirected too many  times (20)
      at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
      at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
      at TestConn.main(TestConn.java:28)
  </code></pre>
  
  <p>Can anyone please help me regarding this exception?</p>