Skip to content

Instantly share code, notes, and snippets.

@graphnode
Created June 3, 2010 13:33
Show Gist options
  • Save graphnode/423887 to your computer and use it in GitHub Desktop.
Save graphnode/423887 to your computer and use it in GitHub Desktop.
var sys = require('sys'),
http = require('http');
function requestGoogle(callback) {
var google = http.createClient(80, 'www.google.com');
var request = google.request('GET', '/', {'host': 'www.google.com'});
request.addListener('response', function (response) {
var data = "";
response.addListener('data', function (chunk) {
data += chunk;
sys.puys('Data received.');
});
response.addListener('end', function (chunk) {
sys.puts('Response ended.');
if (callback != undefined) callback(data);
});
});
request.end();
}
// Example usage:
requestGoogle(function(data) {
sys.puts('Result is ' + data);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment