ESP32 WebServer - How can I read the payload of a POST

I started with the ESP32 WebServer FSBrowser example. It uses POST requests to upload new files to the device's SPIFFS.

I would like to add a new POST handler called /run which accepts some text as the payload of the request and then prints it to the serial port.

The POST request is sent using the following Javascript:

        var xhr = new XMLHttpRequest();"POST", "/run", true);
        xhr.setRequestHeader('Content-Type', 'application/json');

My handleRun function looks like this

void handleRun() {
  DBG_OUTPUT_PORT.println("handleRun called");
  if (server.uri() != "/run") {
  HTTPUpload& upload = server.upload();
  DBG_OUTPUT_PORT.println("server.upload() finished ");
  server.send(200, "text/plain", "");

The output from the serial port suggests that upload.status is not valid:

handleRun called
server.upload() finished
Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.

But I do not understand why.

How do you get the payload out of a POST request using ESP32 WebServer?

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.