-
-
Save Ugmaxie/35f5b154747c6560a7f5 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'); | |
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); | |
function onSuccessLogin(headers){ | |
var post_sms = querystring.stringify({ | |
message: "Your table's ready at Roberts Roadhouse. Please see the host to be seated. test1", | |
phone: "679647513", | |
time: Date.now() | |
}); | |
var h = headers; | |
headers['Content-Type'] = 'application/x-www-form-urlencoded'; | |
headers['Content-Length'] = post_sms.length; | |
var o = options; | |
o.path = '/v.1/smsPage'; | |
o.headers = h; | |
var req_sms = http.request(o, function(res) { | |
console.log('HEADERS2: ' + JSON.stringify(res.headers)); | |
res.setEncoding('utf8'); | |
res.on('data', function (chunk) { | |
console.log('BODY: ' + chunk); | |
}); | |
}); | |
req_sms.on('error', function(e) { | |
console.log('problem with request: ' + e.message); | |
}); | |
req_sms.end(post_sms); | |
console.log(req_sms); | |
} | |
return; |
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 request = require('request'); | |
var login = 'http://localhost:5000/login'; | |
var sms = '/v.1/smsPage'; | |
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('message', "Your table's ready at Roberts Roadhouse. Please see the host to be seated. test1"); | |
form1.append('username', 'admin'); | |
form1.append('password', '123123'); | |
var req_sms = request.post(sms, 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 form2 = req_sms.form(); | |
form2.append('message', "Your table's ready at Roberts Roadhouse. Please see the host to be seated. test1"); | |
form2.append('phone' , "679647513"); | |
form2.append('time', Date.now()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment