Created
May 14, 2012 09:03
-
-
Save momo-lab/2692864 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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