我正在尝试编写一个Node.js脚本,该脚本将返回有关站点的SSL证书的信息,但是每次运行它时,我在浏览器中都看不到任何结果。我也做错了,因为我也没有收到错误。
我在浏览器中看到的只是开始...和结束...
function certInfo(address, callback) {
var https = require('https');
var options = {
host: address,
port: 443,
method: 'GET'
};
var info = ""
var req = https.request(options, function(res) {
info = res.connection.getPeerCertificate();
});
req.on('error', (e) => {
info = e;
});
req.end();
callback(info);
}
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('Starting...');
certInfo('www.google.com', function(result) {
res.write(result);
});
res.write('Ending...');
res.end();
}).listen(80);