Skip to content

Instantly share code, notes, and snippets.

@tony1223
Created August 5, 2012 22:27
Show Gist options
  • Select an option

  • Save tony1223/3267491 to your computer and use it in GitHub Desktop.

Select an option

Save tony1223/3267491 to your computer and use it in GitHub Desktop.
nodejs to submit a http request
require('http');
function wget (host, path, https, callback) {
var port = (https)? 443: 80,
client = http.createClient(port, host, https),
request = client.request('get', path, { 'host': host }),
response_body = [];
request.end();
request.on('response', function (response) {
response.on('data', function (chunk) {
response_body.push(chunk);
});
response.on('end', function () {
callback(response_body.join(""));
});
});
}
wget('github.com', '/xonecas.atom', true, function (atom) {
console.log(atom);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment