Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By rahulmr
#48087 I am using the ESP8266 arduino and have set up a server at port 200 . the IP is also defined for the same as 192.168.1.00

Code: Select allESP8266WebServer server(200);
IPAddress ip(192, 168, 1, 100); //Node static IP
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);



Code: Select allserver.on("/parseIFTTT", parseIFTTT);


void parseIFTTT() {

  String message;
  message += server.args();
  message += "\n";
  for (uint8_t i = 0; i < server.args(); i++) {
    message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
  }
  Serial.println(message);
  server.send(200, "text/plain", "Success  " + message);
}

is done to route the parseIFTTT request to this parseIFTTT() method.

I have done port forwarding and using the duckdns to access this server from outside. This is my duckdns address

http://xxxxxx.duckdns.org:200/parseIFTTT

When I make a POST using a POSTMAN tool with content type as text/plain , the body contents are shown in the serial monitor as

plain
--body contents--

But when the same request is made from IFTTT the serial monitor shows nothing but plain as empty .Initially I felt the issue is with IFTTT. But that is not the issue as when I use the WiFiWebServer example in the arduino , using the following code

Code: Select all String req = client.readString();
  Serial.println(req);
  client.flush();

I see the data from IFTTT as :

Code: Select allPOST /parseIFTTT HTTP/1.1
Content-type: text/plain
host: xxxxxx.duckdns.org:200
content-length: 27
x-newrelic-id: XAMGV15QGwQJVllRDgQ=
x-newrelic-transaction: PxQFA1NbAQQJVwJWA1dSB0YdUFIOFQZOEgEPVA5ZBFYGXAwECFgFAFcUG0MHUwoLBAcDAxVs
Connection: close

{"value":"test data from IFTTT"}



So I believe I am doing something wrong with the server.args(). I am under the impression that server.args() should give the body contents used in the POST whether contentType is text/plain or x-www-form-urlencoded.

Am I doing something wrong or with the server.args() can't we get the body data from the POST request ?
User avatar
By bbx10node
#48096 [quote="rahulmr"]
I see the data from IFTTT as :

Code: Select allPOST /parseIFTTT HTTP/1.1
Content-type: text/plain
host: xxxxxx.duckdns.org:200
content-length: 27
x-newrelic-id: XAMGV15QGwQJVllRDgQ=
x-newrelic-transaction: PxQFA1NbAQQJVwJWA1dSB0YdUFIOFQZOEgEPVA5ZBFYGXAwECFgFAFcUG0MHUwoLBAcDAxVs
Connection: close

{"value":"test data from IFTTT"}


IFTTT is sending JSON. HTTP POST argument should look something like this.

Code: Select allvalue=test data from IFTTT


server.args() works for HTTP POST.
User avatar
By rahulmr
#48098 Thanks for looking into the matter .

It should ideally work but for me what ever content type I send from the IFTTT, the args are not parsing that.

I used the text/plain for the IFTTT and then used just {{Message}} in the Body in the IFTTT and even then the args() returns nothing .

Is that because the POST request from the IFTTT misses something which is required for the parsing of the args ?

I could see the libraries/ESP8266WebServer/src/Parsing.cpp parsing the args. But not yet fully debugged that.
User avatar
By bbx10node
#48101 I do not know much about IFTTT. Try content type: application/x-www-form-urlencoded.

Is that because the POST request from the IFTTT misses something which is required for the parsing of the args ?

Yes, the POST request data is in JSON format instead of application/x-www-form-urlencoded. The ESP8266WebServer library does not parse JSON but it does parse urlencoded form data.