var https = require('https');
var fs=require('fs');
var url=require('url');
var crypto = require('crypto');
var qs = require('querystring');
var cryptUtil = require("./crypt");
var cryptUtil = require("./descrypt");
var post_data={
p:'NrqLkmeQmMBFrO6hmdfJr24hRaLuAq
};
var content =qs.stringify(post_data);
var options = {
/* hostname:url.parse( 'https://www.baidu.com').hostname,*/
hostname:'www.baidu.com',
port:19151,
path:'/queryHomePage',
method:'POST',
key:fs.readFileSync('D:/home/nodes/key.pem'),
cert:fs.readFileSync('D:/home/nodes/test.pem'),
requestCert:true,//请求客户端证书
rejectUnauthorized:false,
headers: {
'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8'
}
};
var req =https.request(options,function (res) {
/* console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));*/
res.setEncoding('utf8');
res.on('data',function (chunk) {
/* var decrypt_text = cryptUtil.des.decrypt(chunk,0);*/
var chunkJson=JSON.parse(chunk).returnObject.toString();//向后台发请求返回的加密数据
var decrypt_text =cryptUtil.des.decrypt(chunkJson);//调用解密方法对返回的数据进行解密
console.log('BODY: ' +decrypt_text);
});
});
req.on('error',function (e) {
console.log('problem with request: ' + e.message);
});
// write data to request body
req.write(content);
req.end();