Re: Example: http get a page?
Posted: Wed Oct 21, 2015 3:09 pm
Thanks a lot, this example really works. I write to thingsepak.com now.
-->
Open Community Forum for ESP8266, Come share Arduino and IoT (Internet of Things)
https://www.esp8266.com/
ESP8266WiFi.init();
var hostname="www.eecs.mit.edu";
ESP8266WiFi.getHostByName(hostname, function(data){
print(ESP8266WiFi.getAddressAsString(data));
});
ESP8266WiFi.init();
var hostname="www.eecs.mit.edu";
var ipn;
ESP8266WiFi.getHostByName(hostname, function(data){
print(ESP8266WiFi.getAddressAsString(data));
ipn=ESP8266WiFi.getAddressAsString(data);
});
var http = require("http");
http.get({
host: ipn,
port: 80,
path: "/"
}, function(response) {
print("get callback!");
response.on('data', function(data) {
print(data);
});
response.on('close', function() {
print("The response connection closed");
});
});
ESP8266WiFi.getHostByName("www.google.com", function(ipAddress) {
// Do something with the ip address
});
var myDesiredIp;
ESP8266WiFi.getHostByName("www.google.com", function(ipAddress) {
myDesiredIp = ipAddress;
});
// (A) ... do some code here
ESP8266WiFi.getHostByName("www.google.com", function(ipAddress) {
// (A) ... do some code here
});