![](/img/trans.png)
[英]Nodejs https request UNABLE_TO_GET_ISSUER_CERT_LOCALLY
[英]Nodejs - “Sending https request to the same domain multiple times” fail to get the SSL cert each time
我正在尝试获取URL的SSL详细信息,并且在请求多个唯一主机时可以使用。
但是,由于某些原因,当请求同一主机时,仅返回第一个请求的证书,而不返回其他请求。
感觉好像存在保持SSL握手状态且无法执行的缓存/会话。
这是复制它的代码:
var request = require('request')
var r = request({
url: 'https://google.com/',
method: 'HEAD',
gzip: true,
followRedirect: false,
followAllRedirects: false
});
r.on('response', function(res) {
certDetails = (res.req.connection.getPeerCertificate())
console.log('*********1st Request**********');
console.log(certDetails);
})
setTimeout (function() {
var r = request({
url: 'https://google.com/',
method: 'HEAD',
gzip: true,
followRedirect: false,
followAllRedirects: false
});
r.on('response', function(res) {
certDetails = (res.req.connection.getPeerCertificate()) // works
console.log('*********2nd Request**********');
console.log(certDetails);
})
}, 5000)
第二个请求在5秒后发送到同一主机,但无法获取证书详细信息。
但是,如果我们将第一个主机保留为google.com,将第二个主机保留为yahoo.com,则两者都将被检索(因为它们是唯一的,并且可能未缓存)。
好的,找到答案了。
可以通过以下方式发送请求:
agent: new Agent({
maxCachedSessions: 0
}),
这样它们就不会被缓存。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.