Skip to content

Instantly share code, notes, and snippets.

@anandsunderraman
Last active December 18, 2015 22:09
Show Gist options
  • Save anandsunderraman/96eeb13aecb34fed7116 to your computer and use it in GitHub Desktop.
Save anandsunderraman/96eeb13aecb34fed7116 to your computer and use it in GitHub Desktop.
Gist to POST a request using node.js request module
var request = require('request');
function postRequest(post_data,responseObject)
{
var url = 'http://www.example.com';
var proxy_opt = 'http://domain:port';
var post_options = {
uri:url,
method: 'POST',
json:true,
proxy: proxy_opt,
headers: {
'Content-Type':'application/json',
},
body: JSON.stringify(post_data)
};
// Set up the request
request.post(post_options,function(err,res,body){
if(err)
{
console.log(err);
}
else
{
responseObject.send(body);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment