我必须使用Java代码将一些jar文件检索到本地,但这是一个特例:
非常感谢!
更新 :
感谢@ EJP的解决方案,我添加了Authenticator
。但后来我被protocol exception: server redirected too many times
困住了。我尝试添加CookieManager
,但没有用。我使用的最终解决方案是:
CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));
URL url = new URL(path);
URLConnection conn = url.openConnection();
conn.setDoInput(true);
InputStream in = null;
byte[] encodedPassword = (login + ":" + pwd).getBytes();
BASE64Encoder encoder = new BASE64Encoder();
conn.setRequestProperty("Authorization", "Basic " + encoder.encode(encodedPassword));
conn.connect();
in = conn.getInputStream();