How do you URL encode parameters in Erlang?

前端 未结 8 1114
清歌不尽
清歌不尽 2020-12-31 01:17

I\'m using httpc:request to post some data to a remote service. I have the post working but the data in the body() of the post comes through as is, without any URL-encoding

8条回答
  •  無奈伤痛
    2020-12-31 01:50

    I encountered the lack of this feature in the HTTP modules as well.

    It turns out that this functionality is actually available in the erlang distribution, you just gotta look hard enough.

    > edoc_lib:escape_uri("luca+more@here.com").
    "luca%2bmore%40here.com"
    

    This behaves like CGI.escape in Ruby, there is also URI.escape which behaves slightly differently:

    > CGI.escape("luca+more@here.com")
     => "luca%2Bmore%40here.com" 
    > URI.escape("luca+more@here.com")
     => "luca+more@here.com" 
    

    edoc_lib

提交回复
热议问题