sending a json body with http:request

Tim Fletcher twoggle@REDACTED
Thu Jan 28 23:55:25 CET 2010


> mochijson2:encode/1 returns binary so do I need to use binary_to_list on it?

I think mochijson2:encode/1 returns an iolist, not a binary. You can
use the iolist_to_binary function to convert to binary.


> Do I need to url encode the Params?

If you're sending content as "application/x-www-form-urlencoded", then
it should be encoded appropriately:

  http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4.1

Note that this is different to the URI encoding defined in RFC 3986.


> Is there a url encoding function in erlang other then edoc_lib:escape_uri/1?

AFAIK, no. That doesn't appear to encode as application/x-www-form-
urlencoded though.


I put together a comparison of several different encoding
implementations here:

  http://github.com/tim/erlang-percent-encoding

Is there a reason the server expects a mixture of JSON *and* form
urlencoded params? Surely it would be easier to just send a JSON
encoded body...


Tim


More information about the erlang-questions mailing list