发现错误
最近在用nodejs发送https请求时候,出现\”error: unable_to_verify_leaf_signature\”
的错误,错误如下:
events.js:72 throw er; // unhandled \'error\' event ^ error: unable_to_verify_leaf_signature at securepair. (tls.js:1381:32) at securepair.emit (events.js:92:17) at securepair.maybeinitfinished (tls.js:980:10) at cleartextstream.read [as _read] (tls.js:472:13) at cleartextstream.readable.read (_stream_readable.js:341:10) at encryptedstream.write [as _write] (tls.js:369:25) at dowrite (_stream_writable.js:226:10) at writeorbuffer (_stream_writable.js:216:5) at encryptedstream.writable.write (_stream_writable.js:183:11) at write (_stream_readable.js:602:24)
错误的原因是:对方数字证书设置不正确,
解决办法: 将rejectunauthorized参数设置成false
var https = require(\'https\'); var options = { hostname: \'www.magentonotes.com\', port: 443, path: \'/\', method: \'get\', rejectunauthorized:false }; var req = https.request(options, function(res) { console.log(\"statuscode: \", res.statuscode); console.log(\"headers: \", res.headers); res.on(\'data\', function(d) { process.stdout.write(d); }); }); req.end(); req.on(\'error\', function(e) { console.error(e); });
参考资料:https://nodejs.org/api/https.html
总结
以上就是关于node.js请求https报错的解决方法,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流。
如对本文有疑问, 点击进行留言回复!!
offset、client、scroll (width,height、left,top、X,Y)
网友评论