我寫了一些代碼從網站下載文件。該代碼工作正常,對測試http url。只要我將URL更改爲https,就會有連接超時。使用Java從HTTPS URL下載文件
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);
如果我將https url複製到瀏覽器中,我被問到我希望保存文件的位置,它工作正常。任何幫助不勝感激。我曾嘗試this但沒有奏效
感謝 克里斯
看一看這裏:http://stackoverflow.com/questions/2642777/trusting-all-certificates-using-httpclient-over-https –