So I've been trying to download a pdf from a url that is password protected. I can visit the webpage using Jsoup because this doesn't support PDF files (the URL is a link to a PDF file). How do I make sure I don't have to re-enter the username and password? I can't use URLConnection because that doesn't allow me to log into the website. Thanks for the help.
System.out.println("opening connection");
URL url = new URL("https://www.HIDDEN.com/ciqdotnet/login.aspx?redirect=%2fCIQDotNet%2fFilings%2fDocumentRedirector.axd%3fversionId%3d" + ID + "%26type%3dpdf%26forcedownload%3dfalse");
InputStream in = url.openStream();
FileOutputStream fos = new FileOutputStream("/Users/HIDDEN/Desktop/fullreport.pdf");
System.out.println("reading file...");
int length = -1;
byte[] buffer = new byte[1024];// buffer for portion of data from
// connection
while ((length = in.read(buffer)) > -1) {
fos.write(buffer, 0, length);
}
fos.close();
in.close();
System.out.println("file was downloaded");
}