sending a json body with http:request

Magnus Henoch magnus@REDACTED
Thu Feb 4 12:18:06 CET 2010

Hynek Vychodil <hynek@REDACTED> writes:

>>> The http request body can be a string or a binary, so no need to call
>>> binary_to_list.
> I think http:request should accept iolist and you don't need neither
> binary_to_list neither iolist_to_binary.

You'd think so :) In the hope of saving someone else the time I spent
debugging this (probably more than once), I'll let you know that
http:request accepts only flat strings and binaries, _not_ iolists.  It
seems to work fine, and the data is actually sent, but the
Content-Length header is calculated using length/1, not iolist_size/1,
so the server will not see the entire body.

(For example, length([$f, $o, $o, "bar"]) is 4, while iolist_size of the
same is 6.  You want the latter.)

Generally, the inets http client increases the amount of suffering in
the world.  You'd be better off using lhttpc instead:

Magnus Henoch, magnus@REDACTED
Erlang Solutions



Since January 1st 2010 Erlang Training and Consulting Ltd. has become ERLANG SOLUTIONS LTD.

More information about the erlang-questions mailing list