[erlang-questions] Re: sending a json body with http:request
Pablo Platt
pablo.platt@REDACTED
Fri Jan 29 00:56:25 CET 2010
I've tried:
binary_to_list(iolist_to_binary(mochijson2:encode(Data)))
It works but there is probably a better way.
You are right about mixing form encoding and json.
________________________________
From: Tim Fletcher <twoggle@REDACTED>
To: erlang-questions@REDACTED
Sent: Fri, January 29, 2010 12:55:25 AM
Subject: [erlang-questions] Re: sending a json body with http:request
> 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
________________________________________________________________
erlang-questions mailing list. See http://www.erlang.org/faq.html
erlang-questions (at) erlang.org
More information about the erlang-questions
mailing list