Is there a library that is able to parse Unicode domain name into IDNA? Like שלום.com ==> http://xn--9dbne9b.com/ ?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
java.net.IDN seems to do the trick. From my Scala console:
scala> java.net.IDN.toUnicode("xn--9dbne9b.com")
res0: java.lang.String = שלום.com
Note that it works on the hostname, not the URL. So you'll have to strip/extract the http://
protocol first.
A quick glance at the documentation reveals it works in the opposite direction too. From above (my Unicode hostname in the variable res0
)
scala> java.net.IDN.toASCII(res0)
res3: java.lang.String = xn--9dbne9b.com