Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - InetSocketAddress hostname with accents

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.

like image 898
Damien Avatar asked Aug 22 '12 14:08

Damien


1 Answers

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.

like image 72
Stephan Avatar answered Nov 09 '22 10:11

Stephan