Chat freely about the open source Javascript projects for ESP8266

User avatar
By hygy
#31657 Hi, can u somebody provide an example how to get a page with the http module?

I used this (connected to internet, the http server example is working), but this is not. (the mcu have a working connection):

var http = require("http");
http.get("http://www.espruino.com", function(res) {
res.on('data', function(data) {
console.log(data);
});
});

HyGy
User avatar
By Erni
#31935
Http client is really not function. I tried a lot too, but without result.


You could try this, it wil give you the index page from http://www.eecs.mit.edu/
But it would be nice if we could use DNS name resolution


Code: Select allESP8266WiFi.init();
var http = require("http");
http.get({
    host: "18.62.0.96",
    port: 80,
    path: "/"
}, function(response) {
    print("get callback!");
    response.on('data', function(data) {
      print(data);
    });
    response.on('close', function() {
       print("The response connection closed");
    });
});