Skip to content

Instantly share code, notes, and snippets.

@dearrrfish
Created June 19, 2015 23:32
Show Gist options
  • Save dearrrfish/d1f0d22e67298731cede to your computer and use it in GitHub Desktop.
Save dearrrfish/d1f0d22e67298731cede to your computer and use it in GitHub Desktop.
Send Request function uses the CURL command line tool
// http://zurb.com/forrst/posts/Alternative_HTTP_Request_method_for_Node_js_usin-Jek
/**
* Send Request
*
* Send Request function uses the CURL command line tool
* rather than Node's built-in HTTP functions because
* it makes specifiying a proxy connection much easier
*/
function send_request(opts, callback) {
var curl = spawn('curl', ['--proxy', 'myproxy.com:1234', '-s', '-S', opts.uri]),
data = '',
err = null;
curl.stdout.on('data', function(chunk) {
data += chunk;
});
curl.stderr.on('data', function(err_msg) {
if (err === null) { err = ''; }
err += err_msg;
});
curl.on('exit', function(exit_code) {
callback(err, err, data);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment