I'm writing a program to download all of my monthly statements from my ISP using HttpClient. I can login to the site, access pages, and download pages but I can't download my PDF statements. It just downloads some HTML. I used the answer to this question to start with. Here is my method where I'm trying to download the PDF:
public void downloadPdf() throws ClientProtocolException, IOException {
HttpGet httpget = new HttpGet("https://www.cox.com/ibill/PdfBillingStatement.stmt?account13=123&stmtCode=001&cycleDate=7/21/2014&redirectURL=error.cox");
HttpResponse response = client.execute(httpget);
System.out.println("Download response: " + response.getStatusLine());
HttpEntity entity = response.getEntity();
InputStream inputStream = null;
OutputStream outputStream = null;
if (entity != null) {
long len = entity.getContentLength();
inputStream = entity.getContent();
outputStream = new FileOutputStream(new File("/home/bkurczynski/Desktop/statement.pdf"));
int read = 0;
byte[] bytes = new byte[1024];
while ((read = inputStream.read(bytes)) != -1) {
outputStream.write(bytes, 0, read);
}
outputStream.close();
}
}
Any help would be greatly appreciated. Thank you!