Ok, I just tried what was basically your code, on a WIZnet device (with the current firmware), connecting to an Apache server:
var eth = require("WIZnet").connect(); var request = function() { var body = ""; var options = { method: 'GET', host: '192.168.1.50', port: 80, path: "/ok.txt", headers: { "Content-Type": "application/json", "Content-Length": body.length } }; var contents = ""; var req = require('http').request(options, function(res) { console.log(res); res.on('data', function(data) { console.log('DATA>'+data); contents += data; }); res.on('close', function() { console.log('CLOSE'); if(res.statusCode === "200" || res.statusCode === "204") { console.log('OK'); } else { console.log('FAIL'); } contents = ""; }); }); req.on('error', function(e) { console.log('Error'); }); req.write(body); req.end(); }; request();
Result is:
{ "headers": { "Date": "Fri, 20 Mar 2015 10:46:45 GMT", "Server": "Apache/2.2.22 (Ubuntu)", "Last-Modified": "Fri, 20 Mar 2015 10:23:31 GMT", "ETag": "\"d44028-3-511b5b54ad422\"", "Accept-Ranges": "bytes", "Content-Length": "2", "Vary": "Accept-Encoding", "Connection": "close", "Content-Type": "text/plain" }, "httpVersion": "1.1", "statusCode": "200", "statusMessage": "OK" } DATA>X CLOSE OK
And it works every time. Any thoughts about what could be different?
What happens when you use Espruino with Apache, rather than Express? Maybe Express is somehow doing something different?
As far as workarounds, if you control the server and we can't figure this our, why not just send a few more bytes?
@Gordon started
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.
Ok, I just tried what was basically your code, on a WIZnet device (with the current firmware), connecting to an Apache server:
Result is:
And it works every time. Any thoughts about what could be different?
What happens when you use Espruino with Apache, rather than Express? Maybe Express is somehow doing something different?
As far as workarounds, if you control the server and we can't figure this our, why not just send a few more bytes?