[erlang-questions] Posting HTTP Form Data with Erlang

Rick Moynihan <>
Wed Aug 18 10:44:40 CEST 2010


On Wed, Aug 18, 2010 at 7:11 AM, Tino Breddin
<> wrote:
> Something like the following might work for you as well:
>
> httpc:request(post, {Url, [], "application/x-www-form-urlencoded, "key=value&key2=value2}, [], []).
>
> If required you could use edoc:escape_uri(String) for the individual values.

Yes, I discovered that shortly after sending the email; prompting me
to write the following function, rather than take on an external
dependency, which I'm a little loathed to do for something so small:

url_encode(Data) ->
    url_encode(Data,"").

url_encode([],Acc) ->
    Acc;

url_encode([{Key,Value}|R],"") ->
    url_encode(R, edoc_lib:escape_uri(Key) ++ "=" ++
edoc_lib:escape_uri(Value));

url_encode([{Key,Value}|R],Acc) ->
    url_encode(R, Acc ++ "&" ++ edoc_lib:escape_uri(Key) ++ "=" ++
edoc_lib:escape_uri(Value)).

Thanks to everyone for your help,

R.


More information about the erlang-questions mailing list