Java - How can I prefer IPv6?

╄→尐↘猪︶ㄣ 提交于 2019-12-02 09:23:42

问题


I want to get the content of http://en.wikipedia.org using java.net.URL's openConnection() method.

I find that en.wikiepdia.org has both IPv4 and IPv6 address:

$ host en.wikipedia.org
en.wikipedia.org is an alias for wikipedia-lb.wikimedia.org.
wikipedia-lb.wikimedia.org is an alias for wikipedia-lb.eqiad.wikimedia.org.
wikipedia-lb.eqiad.wikimedia.org has address 208.80.154.225
wikipedia-lb.eqiad.wikimedia.org has IPv6 address 2620:0:861:ed1a::1

How can I access that site using IPv6 address?


回答1:


-Djava.net.preferIPv6Addresses=true

This jvm argument will work.




回答2:


IPv6 in Java is transparent and automatic. Just provide an an IPv6 address and you'll be good to go. Also check that your jvm does NOT have the following set to true

-Djava.net.preferIPv4Stack=true

More details here:



来源:https://stackoverflow.com/questions/19314241/java-how-can-i-prefer-ipv6

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!