Because the libmicrohttpd library processes POST data in the form, the form submission and parsing in the HTTP protocol have a specific format. However, in our requirements, the data we POST may only be a common XML body, not the data submitted in the form format. We need to process the entire XML body, at this time, libmicrohttpd cannot get the BODY of the entire POST. Tracking the source code, we can add a little bit of code to get the data. The modified source code is as follows:
[Cpp]
/**
* Get a special header value. If multiple
* Values match the kind, return any one of them.
*
* @ Param connection to get values from
* @ Param kind what kind of value are we looking
* @ Param key the header to look for, NULL to lookup 'trailing' value without a key
* @ Return NULL if no such item was found
*/
Const char * MHD_lookup_connection_value (struct MHD_Connection * connection, enum MHD_ValueKind kind, const char * key)
{
Struct MHD_HTTP_Header * pos;
If (NULL = connection)
Return NULL;
If (kind = MHD_POSTDATA_KIND) return connection-> read_buffer; // you only need to add the modified Code.
For (pos = connection-> headers_received; NULL! = Pos; pos = pos-> next)
If (0! = (Pos-> kind & kind ))&&
(Key = pos-> header) | (NULL! = Pos-> header )&&
(NULL! = Key )&&
(0 = strcasecmp (key, pos-> header )))))
Return pos-> value;
Return NULL;
}
/**
* Get a special header value. If multiple
* Values match the kind, return any one of them.
*
* @ Param connection to get values from
* @ Param kind what kind of value are we looking
* @ Param key the header to look for, NULL to lookup 'trailing' value without a key
* @ Return NULL if no such item was found
*/
Const char * MHD_lookup_connection_value (struct MHD_Connection * connection, enum MHD_ValueKind kind, const char * key)
{
Struct MHD_HTTP_Header * pos;
If (NULL = connection)
Return NULL;
If (kind = MHD_POSTDATA_KIND) return connection-> read_buffer; // you only need to add the modified Code.
For (pos = connection-> headers_received; NULL! = Pos; pos = pos-> next)
If (0! = (Pos-> kind & kind ))&&
(Key = pos-> header) | (NULL! = Pos-> header )&&
(NULL! = Key )&&
(0 = strcasecmp (key, pos-> header )))))
Return pos-> value;
Return NULL;
}
At the upper application layer, we can use the following code to obtain the BODY data:
[Cpp]
Const char * length = MHD_lookup_connection_value (connection, MHD_HEADER_KIND, MHD_HTTP_HEADER_CONTENT_LENGTH );
If (length = NULL)
Return NULL;
Const char * body = MHD_lookup_connection_value (connection, MHD_POSTDATA_KIND, NULL );
If (body = NULL)
Return NULL;
Size_t len = strlen (body );
Const char * length = MHD_lookup_connection_value (connection, MHD_HEADER_KIND, MHD_HTTP_HEADER_CONTENT_LENGTH );
If (length = NULL)
Return NULL;
Const char * body = MHD_lookup_connection_value (connection, MHD_POSTDATA_KIND, NULL );
If (body = NULL)
Return NULL;
Size_t len = strlen (body );