Following code sample fails:
var wifi = require("EspruinoWiFi"); var http = require('http'); wifi.connect('yourAP', { password: 'yourPass' }, function(err) { if (err) { throw err; } wifi.getIP(function (err, data) { if (err) { throw err; } console.log(data); var options = { host: 'espruino.com', port: 80, path: '/', method: 'HEAD', }; console.log('about to http request'); http.request(options, function(res) { console.log('request cb'); res.on('data', function(data) { console.log("HTTP> "+data); }); res.on('close', function(data) { console.log(data); console.log("Connection closed"); }); res.on('error', function(err) { console.log(err); }); }).end(); }); });
Produces only:
about to http request request cb false Connection closed
Change it to a GET request and you get:
about to http request request cb HTTP> <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> > Moved Permanently The docu HTTP> ment has moved here. s>Apache/2.4.18 (Ubuntu) Server at espruino.com Port 80 tml> false Connection closed
about to http request request cb HTTP> <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> >
The docu HTTP> ment has moved here.
but I want the HTTP headers not the content.
@dave_irvine 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.
Following code sample fails:
Produces only:
Change it to a GET request and you get:
but I want the HTTP headers not the content.