libmicrohttpd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [libmicrohttpd] Access request body for form post and json parsing


From: Christian Grothoff
Subject: Re: [libmicrohttpd] Access request body for form post and json parsing
Date: Tue, 27 Oct 2015 01:09:13 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.7.0

On 10/26/2015 07:11 PM, Nicolas Mora wrote:
> Hello,
> 
> I'm currently trying to develop a web framework based on MHD. While
> trying to access request body, I have some difficulties to handle it.
> 
> There are 2 different access types: form-based HTTP POST and JSON based
> HTTP REST calls.
> 
> For the first type, if I want to access its value, I can't do it with
> MHD_get_connection_values for a reason I don't undserstand yet.

Because POST data is only available via the PostProcessor.

> If I use MHD_create_post_processor on a well-formed HTTP form-based
> POST, I'm able to parse the POST parameters but in that case, the HTTP
> call must be with a specific content-type.

Sure, because the PP needs to know what format to expect. You may be
able to correct this using MHD_set_connection_value() to fake the
correct header being present for the PP.

> I tried to use upload_data to get raw request body data, but it seems
> not to be filled when I need it.

Please study the docs in more detail. The "upload_data" will be present
between the 2nd and (last-1) call to your callback.

> 
> Basically, I would like to know if there's a way to use
> MHD_get_connection_values (connection, MHD_POST_KIND, ulfius_fill_map,
> post_map); all the time, and also a way to get raw request body to parse
> it in a json format ?

Yes, of course you can get the raw body.
See also
http://www.git.taler.net/?p=mint.git;a=tree;f=src/mint;h=9564617a08d778002092a3c3bececabe23c0c193;hb=HEAD
for an extended long and well-documented real-world example of an HTTPD
parsing JSON bodies.

Happy hacking!

Christian

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]