I want to send data from a client device with javascript to the host an esp32 with Access point. I tried almost everyting (xml, fetch) but couldn't get it to work. Client Javascript (is called in function with button):
fetch('/data_endpoint', {
method: 'POST',
headers: {
'Content-Type': 'text/plain' // Set the content type to plain text
},
body: "some data to send" // Send the plain text data
})
.then(response => response.text())
.then(data => {
console.log(data); // You can handle the response from the ESP32 here
})
console.error('Error:', error);
});
Server side Esp32:
server.on("/data_endpoint", HTTP_POST, [](AsyncWebServerRequest *request){
Serial.println("in func: ");
String data = request->arg("plain");
Serial.println("Received data: " + data);
// Handle the data as needed
request->send(200, "text/plain", "Data received successfully"); });
This is what i get every time. Serial console esp32 with message in func: Received data:
I tried xml, fetch and i can verify the request triggers the server but there is always no data. I have also get requests on the same server and they work fine (a json with fetch).