Regular String to IDNA in Java

南笙酒味 提交于 2019-12-25 09:55:14

问题


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


来源:https://stackoverflow.com/questions/13936510/regular-string-to-idna-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!