如何通过使用Groovy或Java的IPv6访问网站

我试图通过IPv6访问网页,但总是得到一个“NoRouteToHostException:没有路由到主机”。 我尝试了以下内容:

println 'http://[2001:4810:0:0:0:0:0:110]:80/'.toURL().text

结果是:

Caught: java.net.NoRouteToHostException: No route to host
java.net.NoRouteToHostException: No route to host
    at IPv6Tester.run(IPv6Tester.groovy:116)

然后我试着:

def authSite = new groovyx.net.http.HTTPBuilder( 'http://[2620:109:c00d:100:0:0:c765:a381]:80/' )
println authSite.get( path: '/search/users' ) { resp, headers ->
    println "response status: ${resp.statusLine}"
}

导致:

Apr 04, 2015 9:07:14 PM org.apache.http.impl.client.DefaultRequestDirector tryConnect
INFO: I/O exception (java.net.NoRouteToHostException) caught when connecting to {}->http://[2620:109:c00d:100:0:0:c765:a381]:80: No route to host
Apr 04, 2015 9:07:14 PM org.apache.http.impl.client.DefaultRequestDirector tryConnect
INFO: Retrying connect to {}->http://[2620:109:c00d:100:0:0:c765:a381]:80
Apr 04, 2015 9:07:14 PM org.apache.http.impl.client.DefaultRequestDirector tryConnect
INFO: I/O exception (java.net.NoRouteToHostException) caught when connecting to {}->http://[2620:109:c00d:100:0:0:c765:a381]:80: No route to host
Apr 04, 2015 9:07:14 PM org.apache.http.impl.client.DefaultRequestDirector tryConnect
INFO: Retrying connect to {}->http://[2620:109:c00d:100:0:0:c765:a381]:80
Apr 04, 2015 9:07:14 PM org.apache.http.impl.client.DefaultRequestDirector tryConnect
INFO: I/O exception (java.net.NoRouteToHostException) caught when connecting to {}->http://[2620:109:c00d:100:0:0:c765:a381]:80: No route to host
Apr 04, 2015 9:07:14 PM org.apache.http.impl.client.DefaultRequestDirector tryConnect
INFO: Retrying connect to {}->http://[2620:109:c00d:100:0:0:c765:a381]:80
Caught: java.net.NoRouteToHostException: No route to host
java.net.NoRouteToHostException: No route to host
    at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:117)
    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:177)
    at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:304)
    at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:611)
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:446)
    at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:882)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:71)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:220)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:164)
    at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:515)
    at groovyx.net.http.HTTPBuilder.get(HTTPBuilder.java:285)
    at groovyx.net.http.HTTPBuilder$get.call(Unknown Source)
    at IPv6Tester.run(IPv6Tester.groovy:120)

Jsoup也一样:

def profilePage = Jsoup.connect('http://[2001:4810:0:0:0:0:0:110]:80/').userAgent(USER_AGENT).timeout(TIMEOUT).get()

Caught: java.net.ConnectException: No route to host
java.net.ConnectException: No route to host
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:439)
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:424)
    at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:178)
    at org.jsoup.helper.HttpConnection.get(HttpConnection.java:167)
    at org.jsoup.Connection$get$1.call(Unknown Source)
    at IPv6Tester.run(IPv6Tester.groovy:126)

顺便说一句。 如果我从IPv6打开一个Socket到远程IPv6,我可以读取根页面(但不是服务器上的特定路径)。

我假设我必须使用绑定本地IPv6地址的Socket来访问远程IPv6地址,但我找不到这样做的方法。 任何帮助,将不胜感激!


您收到的错误“没有路由到主机”是正确的。

您尝试访问的IP地址都不可路由或可从全球互联网访问。

要解决该问题,请连接到有效的实时IPv6地址。

链接地址: http://www.djcxy.com/p/40613.html

上一篇: How to access website via IPv6 with Groovy or Java

下一篇: About the ip check with ipv4 and ipv6