Unable to use POST with JSON with ESP32


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,

Try this

String jsonData = "{\"level\":" + 40 + "}";