• 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:

    http.get(options, function(res) {
        print("available: " + res.available());                     //returns 168
        print("Content-Length: " + res.headers['Content-Length']);  //returns 300
        var content = "";
        res.on('data', function(data) {  content += data; });
        res.on('close', (data) => print("close: " + content));
        res.on('error', (e) => print("Error: " + e));
    });
    

    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.

About

Avatar for Gordon @Gordon started