我写了一些代码从网站下载文件。该代码工作正常,对测试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 –