如何忽略节点请求中的SSL证书验证? [英] How to ignore SSL certificate validation in node requests?
问题描述
我需要使用node.js对我的某些https
请求禁用对等SSL验证
据我所知,现在我使用的node-fetch
软件包没有该选项.
I need to disable peer SSL validation for some of my https
requests using node.js
Right now I use node-fetch
package which doesn't have that option, as far as I know.
应该类似于CURL的CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false
That should be something like CURL's CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false
任何网络软件包都允许这样做吗?有没有一种方法可以跳过axios中的SSL验证?
Does any networking package allow to do so? Is there a way to skip SSL validation in axios maybe?
推荐答案
Axios到目前为止尚未解决这种情况-您可以尝试:
Axios doesn't address that situation so far - you can try:
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
那是一个非常糟糕的想法,因为它会禁用整个节点服务器上的SSL..
BUT THATS A VERY BAD IDEA since it disables SSL across the whole node server..
或者您可以将axios配置为使用自定义代理,并将该代理的rejectUnauthorized
设置为false
,如所述
or you can configure axios to use a custom agent and set rejectUnauthorized
to false
for that agent as mentioned here
示例:
// At instance level
const instance = axios.create({
httpsAgent: new https.Agent({
rejectUnauthorized: false
})
});
instance.get('https://something.com/foo');
// At request level
const agent = new https.Agent({
rejectUnauthorized: false
});
axios.get('https://something.com/foo', { httpsAgent: agent });
这篇关于如何忽略节点请求中的SSL证书验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!