我在htmlunit上创建了一些内容来阅读网页内容。但是我正在netwer上启用防火墙。我有我可以用来通过防火墙的凭证(我们使用此凭证访问互联网)。我不知道在哪里配置它。 我尝试了以下但它没有用。有什么想法吗?
public class Sparsh {
private WebClient webClient;
private final String userName,password,loginUrl="https://www.google.com";
public Sparsh(String userName,String password)
{
this.userName=userName;
this.password=password;
webClient = new WebClient(BrowserVersion.CHROME);
DefaultCredentialsProvider cp = (DefaultCredentialsProvider)webClient.getCredentialsProvider();
cp.addCredentials("user", "password");
//cp.addProxyCredentials("myuser", "mypasswd");
webClient.getOptions().setUseInsecureSSL(true);
webClient.getOptions().setJavaScriptEnabled(true);
}
public boolean loginCheck() throws IOException
{
final HtmlPage page = webClient.getPage(loginUrl);
System.out.println(page.asText());
if (page.asText().contains("Service Catalog"))
{
return true;
}
return false;
} public static void main(String[] Arg) throws IOException
{
Sparsh snow=new Sparsh("xxxxxx","xxxxxx");
snow.loginCheck();
snow.close();
}
}
我收到以下错误
Exception in thread "main" java.net.UnknownHostException: www.google.com
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:876) at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:876)
at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1229)
at java.net.InetAddress.getAllByName0(InetAddress.java:1180)
at java.net.InetAddress.getAllByName(InetAddress.java:1110)
at java.net.InetAddress.getAllByName(InetAddress.java:1046)
at org.apache.http.impl.conn.SystemDefaultDnsResolver.resolve(SystemDefaultDnsResolver.java:44)
at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:102)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:314)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:363)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:219)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:85)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
at com.gargoylesoftware.htmlunit.HttpWebConnection.getResponse(HttpWebConnection.java:179)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1297)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1214)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:325)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:394)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:379)
at Authentication.Sparsh.loginCheck(Sparsh.java:59)
at Authentication.Sparsh.main(Sparsh.java:113)
Java Result: 1
答案 0 :(得分:0)
您是否可以通过此计算机上的浏览器访问google.com?如果是,则尝试设置代理。
webClient.getOptions.setProxyConfig(new ProxyConfig(proxy_host, proxy_port));
代理用户/密码应与您用于计算机的凭据(例如AD凭据)相同。
确保将域名添加到您的用户名。