Getting POST data in an HTTP server ... #5931
Replies: 1 comment
-
Posted at 2016-09-20 by @gfwilliams Maybe I'm misundertanding, but when it's called the data hasn't arrived yet so available data reports 0? Espruino's event based, so you can't do like on Arduino and just block execution until data arrives. Using the callback as you suggested at the end is the right way to handle it.
Posted at 2016-09-20 by ClearMemory041063 Have a look at this code for some ideas on Post and Get http://forum.espruino.com/conversations/292196/#comment13195299 Posted at 2016-09-20 by Kolban @gfwilliams https://nodejs.org/en/docs/guides/anatomy-of-an-http-transaction/ What you say makes perfect sense now and is (in my opinion) the correct implementation. I'm making notes for what might be a programmer's guide to using Espruino and will cover this area. I had mistakenly assumed that Espruino would have received the whole HTTP transaction before invoking the HTTP server side callback ... but now I understand all it would have to do is receive the HTTP headers before invoking the callback and then the callback has a "stream" reader on the rest of the data. That data may or may not have arrived at the time when the callback is made. ... later ...
Posted at 2017-12-04 by @gfwilliams For anyone else who gets here, there's now a tutorial on HTTP POST and Forms: http://www.espruino.com/Posting+Forms |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2016-09-20 by Kolban
My goal is to write a script that sets up an HTTP server and when I post data in from a client, I want to see that data within Espruino. To that end, I set up the following script:
I then send in a POST request using:
when the request is received by the ESP8266, the message logged is:
From this note two things. The first is that the amount of available bytes is flagged as 0 while the HTTP header says that 5 bytes (what I would expect) was sent.
If I change the code to include:
I do in fact see the data. What is puzzling me is the notion that I had expected
available()
to return 5 for the amount of payload data andresponse.read()
to be able to read that data. Can anyone spot what I might have mis understood?Beta Was this translation helpful? Give feedback.
All reactions