问题描述
我遇到与主机名带有某些重音符号(éèô...)的服务器建立连接的问题。
I encounter a problem establishing a connection with an server that has some accents (é è ô...) in its hostname.
例如:
String oUrl = "www.hôtel.fr";
System.out.println(oUrl);
InetSocketAddress isa = new InetSocketAddress(oUrl.toString(), 80);
System.out.println(isa.isUnresolved());
ISA从未解决。
我尝试对主机进行URLEncode(URLEncoder具有UTF-8字符集,因此主机名为www.h%C3%B4tel.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.
推荐答案
在域名中,变音符号,重音符号等必须通过punycode转换。在您的示例中,它最终以 http://www.xn--htel-vqa.fr/
结尾。未经测试,类可能会有所帮助。
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.
这篇关于Java-带重音符号的InetSocketAddress主机名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!