我无法通过WebClient代理访问http页面。
当我使用URLConnection时没有问题:
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("hostname", 8080));
URLConnection urlConnection = new URL("https://www.google.com/").openConnection(proxy);
BufferedReader bufferedReader = null;
try {
bufferedReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
String line;
while ((line = bufferedReader.readLine()) != null) {
System.out.println(line);
}
} finally {
if (bufferedReader != null) {
bufferedReader.close();
}
}
但是当我尝试使用WebClient时,我遇到了一个错误:
WebClient webClient = new WebClient(BrowserVersion.CHROME, "hostname", 8080);
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
webClient.getOptions().setThrowExceptionOnScriptError(false);
HtmlPage htmlPage = webClient.getPage("https://www.google.com/");
System.out.println(htmlPage.asText());
错误是“需要407代理身份验证.ISA Server需要授权才能完成请求。拒绝访问Web代理筛选器。”
我不明白为什么URLConnection没有身份验证问题。
感谢您的帮助!