How do I save the body of an HTTP request as string and print it? I'm having an HTML file and I'm sending an HTTP request like this:
function loadXMLDoc(str) {
var url = "http://192.168.178.37?" + str;
var http = new XMLHttpRequest();
http.onreadystatechange = function() {
if (http.readyState === 4) {
window.alert(http.response);
}
}
http.open('GET', url, true);
http.send();
}
On the other side the response looks like this:
char rspText[] = "value=sensorvalue";
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: application/x-www-form-urlencoded");
client.printlnf("Content-Length: %d", strlen(rspText));
client.println();
client.print(rspText);
My problem is that the http.response
which should include to body is always empty. I know that I have probably used the wrong Content-Type. I simply want to send a sensor value back in the response and save it as string for later use.
application/x-www-form-urlencoded
. Typical response types areapplication/json
ortext/html
ortext/plain
. Not knowing what your use case is, if you just want a plain string, usetext/plain
.http.status
and make sure it's 200.