Skip to content

Instantly share code, notes, and snippets.

@anistark
Forked from alessioalex/request post node.js
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anistark/03f97b4278fd929fa633 to your computer and use it in GitHub Desktop.
Save anistark/03f97b4278fd929fa633 to your computer and use it in GitHub Desktop.
request post node.js
var request = require('request'), default_headers, site_root = 'http://localhost:3000';;
default_headers = {
'User-Agent': 'Mozilla/5.0 (X11; Linux i686; rv:7.0.1) Gecko/20100101 Firefox/7.0.1',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language': 'en-us,en;q=0.5',
'Accept-Encoding': 'gzip, deflate',
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
// 'Connection': 'keep-alive',
'Cache-Control': 'max-age=0'
};
request({
url: site_root + '/login',
headers: default_headers,
method: 'POST',
body: JSON.stringify({ user:'my_user', password:'my_pass' })
}, function (err, res, body) {
if (!err && res.statusCode == 200) {
console.log(body);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment