1
我是HTMLUnit的新手。我已經嘗試了一些示例來更好地理解HTMLUnit。WebClient代理授權錯誤與HTMLUnit
我正在使用HTMLUnit 2.15版本。
代碼:
final WebClient webClient = new WebClient(BrowserVersion.getDefault(), "***.***.com", portNo);
// set proxy username and password
final DefaultCredentialsProvider credentialsProvider = (DefaultCredentialsProvider) webClient.getCredentialsProvider();
credentialsProvider.addCredentials(username, password);
//credentialsProvider.addNTLMCredentials(username, password, null, -1, "localhost", "domain");
HtmlPage page = null;
try {
page = webClient.getPage("http://htmlunit.sourceforge.net");
} catch (FailingHttpStatusCodeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Google" + page.getTitleText());
當我運行這段代碼我收到以下錯誤消息。
com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException: 407 Proxy Authorization Required for http://htmlunit.sourceforge.net/
at com.gargoylesoftware.htmlunit.WebClient.throwFailingHttpStatusCodeExceptionIfNecessary(WebClient.java:527)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:352)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:407)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:392)
at Main.main(Main.java:46)
Exception in thread "main" java.lang.NullPointerException
at Main.main(Main.java:58)
我知道爲什麼我看到證書後得到代理異常。
我會嘗試舊版本的HTMLUnit看看會發生什麼。這可能是一個錯誤。試試HTMLUnit 2.13 – Arya