HtmlUnit download file

烈酒焚心 提交于 2019-12-21 20:50:16

问题


I am trying to download file via HTMLUnit. But every time when I use code like this:

InputStream stream  = anchor.click().getWebResponse().getContentAsStream();

i get website instead file.

Download link looks like this:

<a id="j_id272:exportToExcel" onclick="if(typeof jsfcljs == 'function'){jsfcljs(document.forms['j_id272'],'j_id272:exportToExcel,j_id272:exportToExcel','');}return false" href="#">
     <img id="j_id272:exportToExcelImage" alt="???exportToExcel???" src="/ECRM/gfx/icon_excel.gif">
</a>

Is there any way to download this?


回答1:


Page page = anchor.click();
BinaryPage bp = new BinaryPage(page.getWebResponse(),page.getEnclosingWindow());
InputStream input = bp.getInputStream();

What is inside your page? Maybe it is a 40X or other 50X error page?




回答2:


If you want get page see below:

  final HtmlPage enclosedPage = (HtmlPage) anchor.click().getEnclosingWindow().getEnclosedPage();


来源:https://stackoverflow.com/questions/25136439/htmlunit-download-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!