Last active
December 18, 2015 22:09
-
-
Save anandsunderraman/96eeb13aecb34fed7116 to your computer and use it in GitHub Desktop.
Gist to POST a request using node.js request module
This file contains hidden or 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
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