Skip to content

Instantly share code, notes, and snippets.

@kixxauth
Created June 26, 2011 11:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kixxauth/1047559 to your computer and use it in GitHub Desktop.
Save kixxauth/1047559 to your computer and use it in GitHub Desktop.
Make a request to an http server
// Call this script with a http URL as the single argument:
// node test_request.js http://www.google.com
var http = require('http');
var url = require('url');
parsed = url.parse(process.argv[2]);
var opts = {
port: 80,
host: parsed.hostname,
path: parsed.pathname,
method: 'GET'
};
var req = http.request(opts, function (res) {
console.log();
console.log('got callback...');
var buff = '';
res.setEncoding('utf8');
res.on('end', function () {
console.log();
console.log('body length:', buff.length);
console.log();
console.log('END');
console.log();
});
res.on('data', function (chunk) {
buff += chunk;
});
console.log();
console.log(res.headers);
});
req.end();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment