-->
Page 1 of 1

[Solved]ESP8266WebServer POST Payload name of data sent

PostPosted: Mon Feb 22, 2016 5:02 am
by gamecompiler
Hi, i would like to get the complete POST Payload posted by a webform to the server.
I use the ESP8266 FSBrowser example.
But with following additions:

Code: Select allvoid testfunc(){
  //Outch, there is no argument inside if zero.
  if(server.args() == 0) return server.send(500, "text/plain", "BAD ARGS");

  for (int x=0; x <= server.args(); x++) {
    //print all arguments received in POST payload
    DBG_OUTPUT_PORT.println(server.arg(x));
  }
  //Print out the amount of arguments received in POST payload
  DBG_OUTPUT_PORT.println(server.args());
  //Make the browser happy, send him something
  server.send(200, "text/plain", "");
}


and this as callback definition located at the setup loop.

Code: Select allserver.on("/test", HTTP_POST, testfunc);


I just get the values of the Payload variables.
I would like to get the names of the variables.

A example of my POST request is here:
Code: Select allnickname: "mynickname"
team: "red"


The code displayed above only outputs:
Code: Select all2
mynickname
red


But i would like to also get nickname and team

Thanks in advance

Re: ESP8266WebServer POST Payload name of data sent

PostPosted: Mon Feb 22, 2016 10:24 am
by eduperez
After a quick look to the source code (https://github.com/esp8266/Arduino/blob ... ebServer.h), looks like "arg(int i)" returns the value of each argument, and "argName(int i)" returns the name of each argument.

Re: ESP8266WebServer POST Payload name of data sent

PostPosted: Mon Feb 22, 2016 1:50 pm
by gamecompiler
eduperez wrote:After a quick look to the source code (https://github.com/esp8266/Arduino/blob ... ebServer.h), looks like "arg(int i)" returns the value of each argument, and "argName(int i)" returns the name of each argument.


Thank you very much ! That was the solution !