Skip to content

Instantly share code, notes, and snippets.

@seanhess
Created January 11, 2013 18:07
Show Gist options
  • Save seanhess/4512738 to your computer and use it in GitHub Desktop.
Save seanhess/4512738 to your computer and use it in GitHub Desktop.
Node HTTP Client
var options = {
hostname: 'www.google.com',
port: 80,
path: '/upload',
method: 'POST'
};
var req = http.request(options, function(res) {
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
});
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
// write data to request body
req.write('data\n');
req.write('data\n');
req.end();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment