I wrote code to download a file from a website. The code works fine with a test http address. As soon as I changed the URL to https, I get the connection time.
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&filename="+filename,new sun.net.www.protocol.https.Handler());
url.openConnection();
InputStream reader = url.openStream();
FileOutputStream writer = new FileOutputStream("C:/downloads/"+filename);
If I copy https-url to the browser, I will be asked where I want to save the file, and it works fine. Any help is greatly appreciated. I tried this one but didn't work
Thank you, Chris
Chris source
share