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

posted @ 2016-02-19 19:08  格通  阅读(254)  评论(0编辑  收藏  举报