How to access website via IPv6 with Groovy or Java

I'm trying to access a webpage via IPv6 but always get a "NoRouteToHostException: No route to host". I tried the following:

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

results in:

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

then I tried:

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}"
}

which resulted in:

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)

The same happens with 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)

Btw. if I open a Socket from my IPv6 to the remote IPv6 I can read the root page (but not a specific path on the server).

I assume that I have to use a Socket with a bound local IPv6 address to access the remote IPv6 Adress but I couldn't find a way to do so. Any help would be appreciated!


The error you received, "No route to host", is correct.

Neither of the IP addresses you are trying to reach is routable or reachable from the global Internet.

To resolve the problem, connect to a valid, live IPv6 address.

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

上一篇: 观察者模式的相反之处是什么?

下一篇: 如何通过使用Groovy或Java的IPv6访问网站