[erlang-questions] decode_packet for the body

Colm Dougan <>
Thu May 28 16:52:34 CEST 2009


On Thu, May 28, 2009 at 3:38 PM, Joel Reymont <> wrote:
> Suppose I repeatedly ran erlang:decode_packet until it returned http_eoh
> (end of headers). I get something like this after accumulating the results.
>
>   {[{http_header,42,'Content-Type',undefined,
>                  <<"application/x-www-form-urlencoded">>},
>     {http_header,38,'Content-Length',undefined,<<"55">>},
>     {http_header,8,'Accept',undefined,<<"*/*">>},
>     {http_header,14,'Host',undefined,<<"localhost:8081">>},
>     {http_header,24,'User-Agent',undefined,
>                  <<"curl/7.19.4 (i386-apple-darwin9.7.0) libcurl/7.19.4
> zlib/1.2.3">>},
>     {http_request,'POST',{abs_path,<<"/publish">>},{1,1}}],
>    %% body that I still need to decode!
>    <<"topic=events&event=test_event&data=%7b\"word\":\"hello\"%7d">>}
>
> Notice that the body of the POST is x-www-form-urlencoded.
>
> Is there a built-in function somewhere to split the body into fields and
> values?

1> httpd:parse_query(binary_to_list(<<"topic=events&event=test_event&data=%7b\"word\":\"hello\"%7d">>)).
[{"topic","events"},
 {"event","test_event"},
 {"data","{\"word\":\"hello\"}"}]

Colm


More information about the erlang-questions mailing list