-->
Page 1 of 3

Example: http get a page?

PostPosted: Sun Oct 18, 2015 9:49 am
by hygy
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

Re: Example: http get a page?

PostPosted: Sun Oct 18, 2015 11:08 am
by kolban
I don't believe the Espruino port to ESP8266 currently provides DNS name resolution ... try using the IP address of the target. See issue #590 (https://github.com/espruino/Espruino/issues/590).

Re: Example: http get a page?

PostPosted: Tue Oct 20, 2015 12:55 pm
by jankop
Http client is really not function. I tried a lot too, but without result.

Re: Example: http get a page?

PostPosted: Wed Oct 21, 2015 12:41 pm
by Erni
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");
    });
});