I am trying encode some Unicode URLs with Punycode. These URLs have a query parameter that contains non-ASCII characters, for example:
https://en.wiktionary.org/w/index.php?title=Clœlia&printable=yes
The problem is, when I try to do it in Java, the resulting URL is wrong:
String link = "https://en.wiktionary.org/w/index.php?title=Clœlia&printable=yes";
link = IDN.toASCII(link);
// -> link = http://en.wiktionary.org/w/index.xn--php?title=cllia&printable=yes-hgf
If I do it this way, the resulting string is different (I don't know why), but is also wrong:
String link = "http://en.wiktionary.org/w/index.php?title=" + IDN.toASCII("Clœlia") + "&printable=yes";
// -> link = http://en.wiktionary.org/w/index.php?title=xn--cllia-ibb&printable=yes
If I copy the address from Chrome and paste it here, I get this URL, which is what I want:
https://en.wiktionary.org/w/index.php?title=Cl%C5%93lia&printable=yes
What did I do wrong here?