[英]Download PDF using Apache HttpClient
我正在編寫一個程序,使用HttpClient從ISP下載我的所有月度報表。 我可以登錄該站點,訪問頁面和下載頁面,但是不能下載我的PDF語句。 它只是下載一些HTML。 我從這個問題的答案開始。 這是我嘗試下載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();
}
}
任何幫助將不勝感激。 謝謝!
HttpClient httpClient = HttpClientBuilder.create().build();
try {
HttpGet request = new HttpGet("https://www.cox.com/ibill/PdfBillingStatement.stmt?account13=123&stmtCode=001&cycleDate=7/21/2014&redirectURL=error.cox");
HttpResponse response = httpClient.execute(request);
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
String filePath = "hellow.txt";
FileOutputStream fos = new FileOutputStream(new File(filePath));
int inByte;
while ((inByte = is.read()) != -1)
fos.write(inByte);
is.close();
fos.close();
} catch (Exception ex) {
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.