我想用Punycode編碼一些Unicode URL。這些URL都包含非ASCII字符的查詢參數,例如:Punycode爲Unicode查詢參數
https://en.wiktionary.org/w/index.php?title=Clœlia&printable=yes
的問題是,當我嘗試做它在Java中,產生的URL是錯誤的:
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
如果我這樣做,這樣,得到的字符串是不同的(我不知道爲什麼),但也是錯誤的:
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
如果我複製從Chrome中的地址,並將其粘貼在這裏,我得到這個URL,這是我想要的:
https://en.wiktionary.org/w/index.php?title=Cl%C5%93lia&printable=yes
我在這裏做錯了什麼?