I'm trying to set up an ESP32 (DOIT ESP32 DEVKIT V1 in the Arduino IDE, with Espressif's WiFi libraries) with the following includes so far:

#include <WiFi.h>
#include <WiFiClient.h>
#include <WiFiAP.h>
#include <HTTPSServer.hpp>
#include <SSLCert.hpp>
#include <HTTPRequest.hpp>
#include <HTTPResponse.hpp>

Now, if I have a callback routine that's set up with

ResourceNode * nodeEchoPost = new ResourceNode("/cmd", "POST", &handleEcho);

how can I parse out the POST request string? On the serial console I get

[HTTPS:I] Request: POST /cmd

which is a debug output from the HTTPSRequest library itself. But I have no clue how to get that '/cmd' string for my own use! I've tried the example code of

byte buffer[256];
size_t s = req->readBytes(buffer, 256);

getting a buffer that only returns garbage, probably because all the request is in the POST statement and the body is empty.

Since all I need is the request-info


to chop up and use, well.. how do I get that out from the library? I've been googling around, and looking in the library header files, without much luck.

Also, is there any advantage to using the WiFiClientSecure library instead, since everything already goes over HTTPS? That's more of a side question, though if it makes it easier to grab the Request string that way, I'm totally fine with accepting that.


I think I found the answer, by looking through examples in the github repo of Hessel's HTTPS library.

In short, this seems to be it:

void handleEcho(HTTPRequest * req, HTTPResponse * res) {

Serial.print("in handleEcho. request is:");

Output from serial console:

"in handleEcho. request is:/cmd?command1=foo&cmd2=bar"

Now I have a plain-text string that I can use plain string commands on to chop up in parts with strtok or similar. I don't mind the extra hassle of finding keywords in the string, I'm happy to just have gotten the damn thing.

Since I have all the data I want in that request, I'll just use req->readBytes as mentioned in examples to empty the buffer and discard all 'body' data.

And someone's gotta agree with me that adding the .c_str() to an already existing function just seems extra complicated. :/


That's a GET and not a POST, so variables are accessible with

auto params = req->getParams();
std::string command1;
std::string cmd2;
bool hascommand1 = params->getQueryParameter("command1", command1);
bool hascmd2 = params->getQueryParameter("cmd2", cmd2);

See example at https://github.com/fhessel/esp32_https_server/blob/master/examples/Parameters/Parameters.ino

The .c_str() is required to transition from std::string to what println needs, not a problem related to the getRequestString() function itself

I came across this question while looking for ways to read actual POST variables, which is not documented (and the source code does not show sign of it)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.