Skip to content

Instantly share code, notes, and snippets.

@Ugmaxie
Created August 11, 2014 17:12
Show Gist options
  • Save Ugmaxie/8839c093c4899d91fca8 to your computer and use it in GitHub Desktop.
Save Ugmaxie/8839c093c4899d91fca8 to your computer and use it in GitHub Desktop.
var http = require('http');
var querystring = require('querystring');
// write data to request body
var post_data = querystring.stringify({
username : 'admin',
password: '123123'
});
var options = {
hostname: 'localhost',
port: 5000,
path: '/login',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': post_data.length
}
};
var req = http.request(options, function(res) {
// console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
return onSuccessLogin(res.headers);
});
});
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
req.end(post_data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment