我有一個應用程序使用Htmlunit,我需要使用PAC文件,但HtmlUnit顯示錯誤,我不知道爲什麼。HTMLUNIT中的錯誤代理自動配置
PAC文件用Javascript編寫,擴展名爲「.cgi」。
的代碼是:
WebClient webClient = new WebClient();
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setActiveXNative(true);
webClient.getOptions().setAppletEnabled(true);
webClient.getOptions().setCssEnabled(false);
webClient.getOptions().setPopupBlockerEnabled(true);
webClient.getOptions().setRedirectEnabled(true);
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setUseInsecureSSL(true);
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
webClient.getOptions().getProxyConfig().setProxyAutoConfigUrl("http://domain/proxy.pac");
HtmlPage currentPage = webClient.getPage(web);
,並且錯誤是:
Exception in thread "main" java.lang.StackOverflowError at java.io.IOException.<init>(IOException.java:58) at java.io.InterruptedIOException.<init>(InterruptedIOException.java:64) at java.net.SocketTimeoutException.<init>(SocketTimeoutException.java:43) at java.net.SocketInputStream.socketRead0(Native Method) at java.net.SocketInputStream.read(SocketInputStream.java:150) at java.net.SocketInputStream.read(SocketInputStream.java:121) at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:160) at org.apache.http.impl.io.SocketInputBuffer.fillBuffer(SocketInputBuffer.java:84) at org.apache.http.impl.io.SocketInputBuffer.isDataAvailable(SocketInputBuffer.java:95) at org.apache.http.impl.AbstractHttpClientConnection.isStale(AbstractHttpClientConnection.java:310) at org.apache.http.impl.conn.ManagedClientConnectionImpl.isStale(ManagedClientConnectionImpl.java:158) at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:432) at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:863) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72) at com.gargoylesoftware.htmlunit.HttpWebConnection.getResponse(HttpWebConnection.java:167) at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1281) at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1198) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:307) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:376) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:361) at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1237) at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1339) at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1198) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:307) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:376) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:361)
有錯誤的更行,但我還沒有推。
任何想法?
此URL是發明。當我檢查代理的真實網址時,瀏覽器使用JavaScript中的代碼下載擴展名爲「.cgi」的文件。也許這是問題嗎? – angelo087
以其他方式,我有一個JavaScript函數的文件(我認爲是自動配置代理),擴展名爲「cgi」,而不是pac(我不知道這是否正確,因爲我不關心代理)。有沒有辦法將這個配置分配給webClient? :( – angelo087
我可以使用HtmlUnit手動分配PAC文件嗎? – angelo087