var options = {
hostname: 'www.example.com',
port: 443,
path: '/',
method: 'GET'
};
var request = https.request(options, function (response) {});
request.end();
如果目标服务器使用的SSL证书是自制的,不是从颁发机构购买的,默认情况下https
模块会拒绝连接,提示说有证书安全问题。在options
里加入rejectUnauthorized: false
字段可以禁用对证书有效性的检查,从而允许https
模块请求开发环境下使用自制证书的HTTPS服务器。