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

Moderator: igrr

User avatar
By andrewzuku
#49650 Hi everyone!

I want to POST a JSON object from my computer and parse it on the ESP8266. Eg:
Code: Select all{
    "preset": "custom",
    "brightness": 63,
    "customPreset": {
        "colour": "#BADA55",
        "animation": "marching ants"
    }
}


If I POST the JSON object as a raw string from my computer using Google Postman to the ESP8266, how do I read that entire string in the ESP8266?

I'm able to step through .arg(i) and .argName(i), but that approach doesn't seem to handle nested objects (i.e.: "customPreset" above).

Andrew
User avatar
By andrewzuku
#49684 Oops... I feel like an idiot :) There was a bug in my code that had me confused about how .arg(i) and .argName(i) worked with JSON objects.

It turns out to be very simple. So for the sake of future searches:

When POST'ing a JSON object to an ESP8266 running as a server, there should only be a single server.arg(i) containg the entire JSON object as a String.

The .argName(i) was "plain" for me (even though I POST'ed with a "content-type" header of "application/json").

I guess you could also use .arg("plain") to get the entire JSON object as a String.
User avatar
By andrewzuku
#49847 Sorry to dig this one back up.

I can send POST data using both Google Postman and a JQuery AJAX call.

I run into problems when sending a post from Node.js. I get zero arguments.

Is reading .arg(0) really I we should be gathering the POST body? Surely there's a better way.
User avatar
By andrewzuku
#49848 Aah. I found what's going on here...

"if POST data starts with { or [ and doesn't contain =, it is placed into plain request argument"
https://github.com/esp8266/Arduino/issues/2129

That seems like a pretty fragile way to read POST data. Does anyone know of a more robust way?