title: Using Java To Download Files From a HTTPS URL
body: <p>I have written some code to download a file from a website.  The code works fine against a test http url.  As soon as I then change the URL to the https, I get a connect time out.</p>
  
  <pre><code>System.setProperty("http.proxyHost","trproxy.rwe.com") ;
  System.setProperty("http.proxyPort", "80") ;
  Authenticator.setDefault (new MyAuthenticator("USER","PW"));
  //URL url = new URL("http","www.treasury.gov",80,"/ofac/downloads/sdn.csv",new    sun.net.www.protocol.http.Handler());  THIS WORKS
  URL url = new URL("https", "downloads.elexonportal.co.uk",443,"/bmradataarchive/download?key=MYKEY&amp;filename="+filename,new sun.net.www.protocol.https.Handler());
  url.openConnection();
  InputStream reader = url.openStream();
  FileOutputStream writer = new FileOutputStream("C:/downloads/"+filename);
  </code></pre>
  
  <p>If I copy the https url into a browser, I am asked where I wish to save the file and it works fine.  Any help greatly appreciated.  I have tried <a href="https://stackoverflow.com/questions/10135074/download-file-from-https-server-using-java">this</a>   but did not work</p>
  
  <p>Thanks
  Chris</p>