我试图通过以下java代码下载JIRA Tempo报告但是失败了。我可以知道可能或如何做到这一点?我认为主要问题是无法获取登录身份验证,因为我只能下载登录页面。感谢。
public static void saveFile(URL url, String file) throws IOException {
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
String password = "XXXXX";
String username = "XXXXX";
return new PasswordAuthentication(username, password.toCharArray());
}
});
InputStream in = url.openStream();
FileOutputStream fos = new FileOutputStream(new File(file));
int length = -1;
byte[] buffer = new byte[1024];
while ((length = in.read(buffer)) > -1) {
fos.write(buffer, 0, length);
}
fos.close();
in.close();
}
public static void main(String args[]) throws IOException {
try {
URL url = new URL("https://XXXX.atlassian.net/TempoProjectBoardXXXX");
String fileName = "report.xls";
saveFile(url, fileName);
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}