Created
June 19, 2015 23:32
-
-
Save dearrrfish/d1f0d22e67298731cede to your computer and use it in GitHub Desktop.
Send Request function uses the CURL command line tool
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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