ESP32 Parse JSON HTTP Post from client


I am currently making my ESP32 project which receives data from an android app using HTTP requests. The ESP32 hosts the webserver as well as the Wifi Access Point. I have been able to send JSONresponses to my android app client when it sends HTTP GET requests as well s receive JSON HTTP Posts from the client (confirmed: context-length matches the length of jsonobject sent). However, I am not able to access HTTP body and parse the json object.

Is there any way to access the body of a JSON HTTP Post? if so, what libraries are involved? Code snippets would be very helpful.

P.S. My code is just a modified version of the ESP32 WifiAccessPoint example code which identifies the type of HTTPrequest and sends JSON HTTP response if the request is an HTTP GET. Should I post the code?


I have more or less the same question.

My sister is handicap and I would like to create one button that will switch on the TV , go to a preset and adjust the volume to a certain level.

With POSTMAN or REST CLIENT it works , but in my program , I am unable to send this in a way that ARDUINO ESP32 understand it.

If I am able to understand how to translate this for this command , I will be able to code it for the rest.

Content-Type: application/json


I have try this :

String jsonData = {"level:" + (40) };

http.begin(" HTTP/1.1"); //Specify request destination
http.addHeader("Content-Type", "application/json" , "Content-Length", jsonData.length()); //Specify content-type header

Serial.println( " POSTing to Server...");

int httpCode = http.POST(jsonData); //Send the request
String payload = http.getString(); //Get the response payload

Serial.println(httpCode); //Print HTTP return code
//Serial.println(payload); //Print request response payload

http.end(); //Close connection

But I receive a ERROR 400

Thank You in advance for your help.

Best Regards,

Didier, I answered on your other topic. On this topic, the question is not the same as your question. Your question is about setting the contents of the body of the request. This question is about getting the contents of the body of the request, the opposite action.

On this forum you should:
Not post to old topics. A warning message appears on old topics about this.
Not hijack the topics of other fotum members with your own questions. Make your own topic and include a link to an old topic if you believe it is relavent.
Not post the same question in two places. This is called cross-posting and can result in a ban from the forum.
Always use code tags.