I am working on ESP32, New to this device.
I am currently facing the following error. when I try to read the data from request->value().c_str() the serial monitor shows me guru meditation error error SS of error:
My code:
server.on("/register", HTTP_POST, [](AsyncWebServerRequest *request) {
request->send(200, "text/plain", Register(request->getParam("plain",true)).c_str());});
The function:
string Register(AsyncWebParameter *request){
const size_t bufferSize = JSON_OBJECT_SIZE(1) + 250;; StaticJsonDocument data; deserializeJson(data, request->value().c_str()); // facing issue here when request->value().c_str() is called const char* name = data["username"];
return String("Execution complete"); }
I have return simple javascript function to call the API:
function Register() {
const tosend={
"username":"Mohit",
"password":"Mohit10#",
"lastname":"mhatre",
"firstname":"Mohit"
};
const url="http://192.168.2.120/register";
fetch(url, {
method: 'post',
headers: {
// if you want to set
},
body: tosend
})
.then(
function(response) {
response.json().then(function(data) {
console.log(data);
});
}
)
.catch(function(err) {
console.log('Fetch Error :-S', err);
});
}
Can someone please help me resolve the issue i am new to this and stuck here from yesterday
Aucun commentaire:
Enregistrer un commentaire