I'm using standard httpc client in erlang, for sending/receiving request to some service. Sometimes I have a Cyrillic path in my URL. How can I URL-encode Cyrillic URLs?
Thank you.
~/erl$erl
Erlang R14B04 (erts-5.8.5) [source] [64-bit] [smp:2:2] [rq:2] [async-threads:0] [hipe] [kernel-poll:false]
Eshell V5.8.5 (abort with ^G)
1> Encoded = edoc_lib:escape_uri("абвгдеё").
"%c0%b0%c0%b1%c0%b2%c0%b3%c0%b4%c0%b5%c1%91"
2> http_uri:decode(Encoded).
[192,176,192,177,192,178,192,179,192,180,192,181,193,145]
You may use list_to_binary to use as binary.
I had some troubles with the escape_uri from edoc lib.
So I ended up writing one that works with utf-8:
https://stackoverflow.com/a/12648499/113112
https://gist.github.com/3796470
Ex.
Eshell V5.9.1 (abort with ^G)
1> c(encode_uri_rfc3986).
{ok,encode_uri_rfc3986}
2> encode_uri_rfc3986:encode("абвгдеё").
"%d0%b0%d0%b1%d0%b2%d0%b3%d0%b4%d0%b5%d1%91"
3> edoc_lib:escape_uri("абвгдеё").
"%c0%b0%c0%b1%c0%b2%c0%b3%c0%b4%c0%b5%c1%91" # output wrong: À°À±À²À³À´ÀµÁ‘