Java:使用htmlunit

时间:2016-02-01 14:41:11

标签: java eclipse htmlunit

我正在尝试使用Htmlunit / webclient等访问虚拟机上的网页。我的代码暂时正在这样做。

运行程序时,出现以下错误:

  

线程中的异常" main" org.apache.http.conn.HttpHostConnectException:拒绝与https://www.google.com的连接       at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:158)       在org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:149)       在org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:121)       at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:573)       在org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:425)       在org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)       在org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:776)       在com.gargoylesoftware.htmlunit.HttpWebConnection.getResponse(HttpWebConnection.java:152)       在com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1439)       在com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1358)       在com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:307)       在com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:373)       在com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:358)       at autoPEC.main(autoPEC.java:7)   引起:java.net.ConnectException:连接超时:连接       at java.net.DualStackPlainSocketImpl.connect0(Native Method)       在java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)       在java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)       at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)       在java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)       在java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)       在java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)       在java.net.Socket.connect(Socket.java:589)       在sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:649)       at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:375)       at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:148)       ......还有13个

问题:当我在笔记本电脑上(在虚拟机之外)的eclipse上运行相同的代码时,代码运行正常,没有任何错误。

任何人都可以解释为什么我在虚拟机上得到这个?因为代码似乎很好。是否有一些安全措施阻止我的VM上的IDE访问该网站或其他东西?我的防病毒软件?

如何访问虚拟机上的网站,就像我在虚拟机外部访问网站一样?

0 个答案:

没有答案