最近,node.js新增了一个功能,该功能允许使用自定义功能覆盖主机名检查。它已添加到v0.11.14,并将在下一个稳定版本(0.12)中可用。现在,您可以执行以下操作:
var options = { host: '192.168.178.31', port: 3000, ca: [ fs.readFileSync('server-cert.pem') ], checkServerIdentity: function (host, cert) { return undefined; }};options.agent = new https.Agent(options);var req = https.request(options, function (res) { //...});现在,它将接受任何服务器身份,但仍会加密连接并验证密钥。
请注意
,在以前的版本(例如
v0.11.14)中,
checkServerIdentity会返回,
boolean指示服务器的有效性。如果存在问题并且有效,则已将其更改为(之前
v4.3.1)为功能
return(未显示
throw)错误
undefined。



