Skip to content

Instantly share code, notes, and snippets.

@valorkin
Forked from Ugmaxie/http
Last active August 29, 2015 14:05
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 valorkin/7d936141f6d791db03be to your computer and use it in GitHub Desktop.
Save valorkin/7d936141f6d791db03be to your computer and use it in GitHub Desktop.
var http = require('http');
var querystring = require('querystring');
var post_data = querystring.stringify({
username : 'demo',
password: 'demo'
});
var options = {
hostname: 'tableready.herokuapp.com',
port: 80,
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('HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
});
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
req.end(post_data);
var request = require('request');
var login = 'http://tableready.herokuapp.com/login';
var req_login = request.post(login, function optionalCallback(err, httpResponse, body) {
if (err) {
return console.error('npm request err:', err);
}
console.log('npm request response:', body);
console.log('npm request headers:', httpResponse.headers);
});
var form1 = req_login.form();
form1.append('username', 'demo');
form1.append('password', 'demo');
@valorkin
Copy link
Author

  1. node and npm should be installed
brew install node
  1. save app-http.js to file
    run from terminal
node app-http.js
  1. save app-request.js to file
    run from termianl
npm install request
node app-request.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment