Created
August 11, 2014 17:12
-
-
Save Ugmaxie/8839c093c4899d91fca8 to your computer and use it in GitHub Desktop.
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 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