Java - InetSocketAddress hostname with accents

浪尽此生 提交于 2019-12-10 13:07:49

问题


I encounter a problem establishing a connection with an server that has some accents (é è ô...) in its hostname.

For example :

String oUrl = "www.hôtel.fr";   
System.out.println(oUrl);
InetSocketAddress isa = new InetSocketAddress(oUrl.toString(), 80);
System.out.println(isa.isUnresolved());

The ISA is never resolved. It works for www.google.fr.

I tried to URLEncode the host (URLEncoder with UTF-8 charset, so hostname is www.h%C3%B4tel.fr) with no result.

Does anybody have some clues ? I don't find anything on the web.

Thanks and sorry for my english.


回答1:


In domain names, umlauts, accents, etc must be converted by punycode. In your example it would end up in http://www.xn--htel-vqa.fr/. Without having it tested, the IDN class might be of help.



来源:https://stackoverflow.com/questions/12075828/java-inetsocketaddress-hostname-with-accents

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