-
-
Save valorkin/7d936141f6d791db03be to your computer and use it in GitHub Desktop.
This file contains 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 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); |
This file contains 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'); | |
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'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
run from terminal
run from termianl