Nodejs http send POST request
varHTTP = require (' http ');
functionEpay (params)
{
Console.log ("COME in");
varparams = Json.stringify ({
"Sign": "exdycut6lgrkgshuayoxftmdudyvmyffu7grhprwb/dbwm6cybe9sr2rti1/sjwpcdxlowihwej9ifkpk+3ieku/mknqeh1oph/ 4mem59w314jql3/sps+x8qseinj7osfxcfokxjxtw+wevbobhep4sbiakgljvrysg1/bv7ck= "});
varOptions = {
Host: ' 127.0.0.1 ',
PORT:80,
Path: '/index/',
Method: ' Post ',
Headers: {
' Content-type ': ' application/x-www-form-urlencoded ',
' Content-length ':p arams.length
}};
//Send using HTTP
varreq = http.request (options,function(RES) {
Console.log (' STATUS: ' + res.statuscode);
Console.log (' HEADERS: ' + json.stringify (res.headers));
//Set character encoding
Res.setencoding (' UTF8 ');
//Return Data stream
var_data= "";
//Data
Res.on (' Data ',function(Chunk) {
_data+=chunk;
Console.log (' BODY: ' + chunk);
});
//End Callback
Res.on (' End ',function(){
Console.log ("Reboak:", _data)
});
//Error callback//This must have. Or there will be a lot of trouble .
Req.on (' Error ',function(e) {
Console.log (' Problem with request: ' + e.message);
});
});
Req.write (params + "\ n");
Req.end ();
}
Exports.epay=epay;
//index.js main Entrance
varEpay = require ('./epay ');
Console.log (' Stert epaying ');
Epay.epay ("");
CMD into the node command.
>node Index.js
Nodejs HTTP Send POST request