Skip to content

Instantly share code, notes, and snippets.

@momo-lab
Created May 14, 2012 09:03
Show Gist options
  • Save momo-lab/2692864 to your computer and use it in GitHub Desktop.
Save momo-lab/2692864 to your computer and use it in GitHub Desktop.
var util = require('util');
var url = require('url');
var http = require('http');
function download(u) {
u = url.parse(u)
var client = http.createClient(u.port || 80, u.hostname);
var req = client.request('GET', u.pathname, {host: u.hostname});
req.end();
req.on('response', function(res) {
console.log(res.statusCode);
for (var key in res.headers) {
console.log(key + ': ' + res.headers[key]);
}
console.log();
res.setEncoding('UTF-8');
res.on('data', function(chunk) {
util.print(chunk);
});
res.on('end', function() {
console.log();
});
});
}
download("http://www.google.co.jp/")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment