[GH-ISSUE #1506] QUESTION: How to get post data #1285

Closed
opened 2026-02-28 01:29:25 +03:00 by kerem · 2 comments
Owner

Originally created by @ByronAP on GitHub (Sep 28, 2022).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1506

Hardware

WiFimanager Branch/Release: Master
Hardware: ESP32

Description

Does anyone have an example on how to get post data?

I use
wm.server->on("/saveschedule", HTTP_POST, handleSaveScheduleRoute);

and

void handleSaveScheduleRoute()
    {
#if defined(DEBUG)
        Serial.println("[HTTP] handle save schedule");
#endif
        wm.server->send(200, "text/html", "hello you are at save schedule");
    }

which for some reason catches both get and post... but anyway I do not see a way to access the post data, anyone have an example on how to do this?

Thank you :-)

Originally created by @ByronAP on GitHub (Sep 28, 2022). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1506 #### Hardware WiFimanager Branch/Release: Master Hardware: ESP32 ### Description Does anyone have an example on how to get post data? I use `wm.server->on("/saveschedule", HTTP_POST, handleSaveScheduleRoute);` and ``` void handleSaveScheduleRoute() { #if defined(DEBUG) Serial.println("[HTTP] handle save schedule"); #endif wm.server->send(200, "text/html", "hello you are at save schedule"); } ``` which for some reason catches both get and post... but anyway I do not see a way to access the post data, anyone have an example on how to do this? Thank you :-)
kerem closed this issue 2026-02-28 01:29:25 +03:00
Author
Owner

@ByronAP commented on GitHub (Sep 29, 2022):

OK so looking at the code the answer is quite simple since WM is using the default WebServer.h thus checking for a 'plain' argument to see if raw data was sent then getting the contents of the 'plain' arg works perfectly. (using String type may cause an issue in some cases)

Example handler:

void handlePostDataRoute()
    {
        if (wm.server->hasArg("plain") == false)
        {
            // no raw data posted
            wm.server->send(400);
            return;
        }

        // this is the data
        String body = wm.server->arg("plain");

        Serial.println(body);

        // return success
        wm.server->send(204);
    }

<!-- gh-comment-id:1261654643 --> @ByronAP commented on GitHub (Sep 29, 2022): OK so looking at the code the answer is quite simple since WM is using the default WebServer.h thus checking for a 'plain' argument to see if raw data was sent then getting the contents of the 'plain' arg works perfectly. (using String type may cause an issue in some cases) Example handler: ``` void handlePostDataRoute() { if (wm.server->hasArg("plain") == false) { // no raw data posted wm.server->send(400); return; } // this is the data String body = wm.server->arg("plain"); Serial.println(body); // return success wm.server->send(204); } ```
Author
Owner

@tablatronix commented on GitHub (Sep 29, 2022):

This is really an esp webserver question

<!-- gh-comment-id:1262388908 --> @tablatronix commented on GitHub (Sep 29, 2022): This is really an esp webserver question
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/WiFiManager#1285
No description provided.