NEWBIE Unable to use POST with JSON with ESP32 on ARDUINO
Posted: Wed Aug 19, 2020 7:09 am
Hello,
Sorry for my newbie question.
I have a small project to send and adjust the volume automatically depending the surrounding noise.
I have been watching many videos on this topic and reading a lot of information on GOOGLE without any success.
I do not think it is so difficult since it works POSTMAN and REST CLIENT, it is just me that can not translate it in ARDUINO.
This works in POSTMAN and REST CLIENT , I receive a code 200 back.
PUT http://192.168.100.34:8080/BeoZone/Zone ... aker/Level HTTP/1.1
Content-Type: application/json
{
"level":30
}
I have try this :
I receive this error :
500
{"error":{"type":"SERVER_ERROR","message":"JSON error: The document root must be either object or array. (@ offset=0): 2. Json[0:20]: level,30"}}
If I add HTTP/1.1 at the end , I receive a ERROR 400
http://192.168.100.34:8080/BeoZone/Zone ... aker/Level HTTP/1.1
400
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.</p>
</body></html>
Thank you in advance for your help.
Best Regards,
Didier
Sorry for my newbie question.
I have a small project to send and adjust the volume automatically depending the surrounding noise.
I have been watching many videos on this topic and reading a lot of information on GOOGLE without any success.
I do not think it is so difficult since it works POSTMAN and REST CLIENT, it is just me that can not translate it in ARDUINO.
This works in POSTMAN and REST CLIENT , I receive a code 200 back.
PUT http://192.168.100.34:8080/BeoZone/Zone ... aker/Level HTTP/1.1
Content-Type: application/json
{
"level":30
}
I have try this :
- if(WiFi.status()== WL_CONNECTED){
- HTTPClient http;
- http.begin("http://192.168.100.34:8080/BeoZone/Zone/Sound/Volume/Speaker/Level/");
- http.addHeader("Content-Type", "application/json");
- int httpResponseCode = http.PUT("level,30");
- if(httpResponseCode>0){
- String response = http.getString();
- Serial.println(httpResponseCode);
- Serial.println(response);
- }else{
- Serial.print("Error on sending PUT Request: ");
- Serial.println(httpResponseCode);
- }
- http.end();
- }else{
- Serial.println("Error in WiFi connection");
- }
- delay(10000);
- }
500
{"error":{"type":"SERVER_ERROR","message":"JSON error: The document root must be either object or array. (@ offset=0): 2. Json[0:20]: level,30"}}
If I add HTTP/1.1 at the end , I receive a ERROR 400
http://192.168.100.34:8080/BeoZone/Zone ... aker/Level HTTP/1.1
400
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.</p>
</body></html>
Thank you in advance for your help.
Best Regards,
Didier