I believe by doing the read you may be pulling data out that should be going to the data event, and when you are concatenating the data into tempMsg you seem to be printing End of Message after the very first data event.
But basically:
The callback for get/request gets called after the header is received - and not when all data has come in. It's then up to you to add a data handler and handle the data as it comes in.
The reasoning is it's pretty common for HTTP requests to send more data than would fit in the device's RAM, so by leaving the handling of the data up to you, you can decide what is done with it.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Can you try just going with what's done in all the examples? http://www.espruino.com/Internet
Eg. remove
print("Manual read: " + res.read())
, concat all the data, and ONLY print it on close:I believe by doing the read you may be pulling data out that should be going to the
data
event, and when you are concatenating the data into tempMsg you seem to be printingEnd of Message
after the very firstdata
event.But basically:
The callback for get/request gets called after the header is received - and not when all data has come in. It's then up to you to add a
data
handler and handle the data as it comes in.The reasoning is it's pretty common for HTTP requests to send more data than would fit in the device's RAM, so by leaving the handling of the data up to you, you can decide what is done with it.