[En-Nut-Discussion] Webserver via POST

Ole Reinhardt ole.reinhardt at embedded-it.de
Tue May 3 11:04:27 CEST 2011


Hi Werner,

> actually I want to import Files via html-Form over POST. I've already
> found an example in the NutWiki to implement POST Forms in Ethernut. But
> my question is, how far is the implementation of POST functions already
> included in ethernut? Is there an function to read in the POST stream
> available? In the example it is mentioned: "Early versions of the Nut/OS
> API did not directly support the POST method when processing a form
> submit" but what is the early version? :) 

Look at the following example, which is just code snipped of a project:

int CGI_RS232(FILE * stream, REQUEST * req)
{
    if (req->req_method == METHOD_POST) {
        char *name;
        char *value;
        int idx;
        int count;

        NutHttpProcessPostQuery(stream, req);
        count = NutHttpGetParameterCount(req);


        for (idx = 0; idx < count; idx++) {
            name  = NutHttpGetParameterName(req, idx);
            value = NutHttpGetParameterValue(req, idx);

            if (strcmp(name, "baud") == 0) {
                sysconfig->rs232.baudrate = atol(value);
            }
            if (strcmp(name, "data") == 0) {
                sysconfig->rs232.databits = atoi(value);
            }
            if (strcmp(name, "parity") == 0) {
                if (strcmp(value, "none") == 0) {
                    sysconfig->rs232.parity = 0;
                } else
                if (strcmp(value, "odd") == 0) {
                    sysconfig->rs232.parity = 1;
                } else
                if (strcmp(value, "even") == 0) {
                    sysconfig->rs232.parity = 2;
                }        
            }
            if (strcmp(name, "stop") == 0) {
                sysconfig->rs232.stopbits = atoi(value);
            }
        }

As you see, the magic is just the call to NutHttpProcessPostQuery();

Indeed handling a POST request is still missing in the httpd sampel. We
realy should add some demo code there. I'll also update the WIKI entry.

Regards,

Ole




-- 

Thermotemp GmbH, Embedded-IT

Embedded Hard-/ Software and Open Source Development, 
Integration and Consulting

http://www.embedded-it.de

Geschäftsstelle Siegen - Steinstraße 67 - D-57072 Siegen - 
tel +49 (0)271 5513597, +49 (0)271-73681 - fax +49 (0)271 736 97

Hauptsitz - Hademarscher Weg 7 - 13503 Berlin
Tel +49 (0)30 4315205 - Fax +49 (0)30 43665002
Geschäftsführer: Jörg Friedrichs, Ole Reinhardt
Handelsregister Berlin Charlottenburg HRB 45978 UstID DE 156329280 




More information about the En-Nut-Discussion mailing list