I'm working on a simple REST server. I made method to handle http://<esp8266_IP>/test
. The GET method works like a charm and I got the response. Then I tried to send a POST with a JSON data (I used PostMan) but I cannot read anything.
Searching online I read ESP8266 library cannot parse JSON and in that case I can found plain text into server.arg("plain")
. I tried that but no success
How can I read the data into the POST method?
ESP8266WebServer server(80);
...
void handleTest()
{
if (server.method() == HTTP_GET)
{
...
}
else if (server.method() == HTTP_POST)
{
String message = "POST\nHeaders:\n";
for (uint8_t i = 0; i < server.headers(); i++)
{
message += server.headerName(i) + ": " + server.header(i) + "\n";
}
message += "\nRequest params:\n";
for (uint8_t i = 0; i < server.args(); i++){
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
}
server.send(202, "text/plain", message);
}
}
...
void setup()
{
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
if (MDNS.begin("esp8266")) {
Serial.println(F("[Server] MDNS responder started"));
}
server.on("/test", handleTest);
}
-
2Please show your code.Mark Smith– Mark Smith06/16/2017 18:10:15Commented Jun 16, 2017 at 18:10
-
i'm not sure it can do that, aside from uploading files...dandavis– dandavis06/17/2017 01:10:18Commented Jun 17, 2017 at 1:10
-
@MarkSmith I don't think it will be usefull, btw I paste a section of code in my question.Noisemaker– Noisemaker06/17/2017 07:25:29Commented Jun 17, 2017 at 7:25
1 Answer 1
Instead of using below in handleTest()
else if (server.method() == HTTP_POST)
try using below in setup()
server.on("/test", POST, handleTest);