【发布时间】:2014-10-14 06:15:31
【问题描述】:
我正在尝试使用 HtmlUnit 2.15 API 在我的 Java 程序中访问此 Ajax page,但尝试时失败获取页面。我认为原因是对位于here 的这个损坏/丢失的file 的网站请求。
我的代码:
public class HtmlUnitExample {
public static void main(String[] args) throws Exception, FailingHttpStatusCodeException, MalformedURLException, IOException, InterruptedException {
WebClient webClient = new WebClient(BrowserVersion.FIREFOX_24);
webClient.getOptions().setTimeout(120000);
webClient.waitForBackgroundJavaScript(60000);
webClient.getOptions().setRedirectEnabled(true);
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setCssEnabled(true);
webClient.getOptions().setUseInsecureSSL(true);
webClient.getOptions().setDoNotTrackEnabled(true);
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
String url = "http://www.santanderuniversidades.com.br/JuriPopular/index.aspx?idprojeto=16";
final HtmlPage page = (HtmlPage) webClient.getPage(url); //Fails here
System.out.println(page.asXml());
}
}
错误信息:
Exception in thread "main" java.io.EOFException: Unexpected end of ZLIB input stream
at java.util.zip.InflaterInputStream.fill(InflaterInputStream.java:240)
at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:158)
at java.util.zip.GZIPInputStream.read(GZIPInputStream.java:116)
at java.io.FilterInputStream.read(FilterInputStream.java:107)
at org.apache.http.client.entity.LazyDecompressingInputStream.read(LazyDecompressingInputStream.java:68)
at com.gargoylesoftware.htmlunit.HttpWebConnection.downloadContent(HttpWebConnection.java:693)
at com.gargoylesoftware.htmlunit.HttpWebConnection.downloadResponseBody(HttpWebConnection.java:675)
at com.gargoylesoftware.htmlunit.HttpWebConnection.getResponse(HttpWebConnection.java:201)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1313)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1230)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:338)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:407)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:392)
at HtmlUnitExample.main(HtmlUnitExample.java:42)//getPage line
css的页面链接:
<link href='/JuriPopular/App_Themes/estilo/css.axd?files=jPages.css,estilo.css,jquery.fancybox.css' type='text/css' rel='stylesheet' />
调用缺失字体的cssfile:
@font-face{font-family:'DigitalDotRoadsign';
src:url('fonts/DigitalDotRoadsign.eot');
src:url('fonts/DigitalDotRoadsign.eot?#iefix') format('embedded-opentype'),
url('fonts/DigitalDotRoadsign.woff') format('woff'), //call missing file
url('fonts/DigitalDotRoadsign.ttf') format('truetype'),
url('fonts/DigitalDotRoadsign.svg#svgDigitalDotRoadsign') format('svg');
font-weight:normal;
}
这是我问题的根源吗?如果是这样的话,有没有办法避免呢?也许忽略/消除问题的原因?
【问题讨论】:
标签: java javascript css ajax htmlunit