在 unirest (NodeJS) 中禁用 SSL 证书检查
问题:
你想用 unirest 发出 HTTP 请求,如下所示:
unirest_example.js
const unirest = require('unirest');
unirest.get("https://mydomain.net").end(console.log)但你遇到以下错误:
unirest_error.txt
{ error:
{ Error: unable to verify the first certificate
at TLSSocket.<anonymous> (_tls_wrap.js:1088:38)
at emitNone (events.js:86:13)
at TLSSocket.emit (events.js:188:7)
at TLSSocket._finishInit (_tls_wrap.js:610:8)
at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:440:38) code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE' } }解决方案
你可以通过像这样使用 strictSSL(false) 来解决此问题:
unirest_example_strictssl.js
const unirest = require('unirest');
unirest.get("https://mydomain.net")
.strictSSL(false)
.end(console.log)但请注意,这可能会对你的应用程序的安全性产生负面影响,因为此请求将容易受到中间人攻击。
Check out similar posts by category:
Javascript
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow