erlang转化中文为url

今天使用http get 方法时,参量中有中文而导致出错。

例如http://abc.com/abc?arg=中文,在erlang使用http:request方法失败。

后来查了url的规范,url中要使用ascii字符,从而写了下面的方法:

lists:append([io_lib:format("%~.16B", [E]) || E <- binary_to_list(unicode:characters_to_binary("中文"))])。

上面转化的字符追加到url末尾就可以了。

使用post方法可以参考:

how to support chinese in http request body? erlang

原文地址:https://www.cnblogs.com/getong/p/5201987.html