繁体   English   中英

Nodejs Fetch API:无法验证第一个证书

[英]Nodejs Fetch API: unable to verify the first certificate

我在我的 Philips Hue 项目中使用 fetch API 模块,当我调用本地 ip 地址(我的集线器)时,它会在标题中产生该错误。

const fetch = require('node-fetch');
const gateway = "192.168.0.12";
const username = "username";

let getLights = function(){
    fetch(`https://${gateway}/api/${username}/lights`, {
        method: 'GET'
    }).then((res) => {
        return res.json();
    }).then((json) => {
        console.log(json);
    });
}


module.exports = {getLights};

任何安全修复最终都会将 go 放到公共互联网上,让我可以从任何地方访问我的灯吗?

您似乎尝试使用 HTTPS 访问它。 最有可能在您的本地网络上它将是 HTTP

因此,通过将https://${gateway}/api/${username}/lights更改为http://${gateway}/api/${username}/lights应该可以工作。

如果您想保留它 HTTPS 那么您将必须在您的网络上安装 SSL 证书颁发机构。
如果你想完成这些,这些可能是有用的资源:

https://www.freecodecamp.org/news/how-to-get-https-working-on-your-local-development-environment-in-5-minutes-7af615770eec/

https://letsencrypt.org/docs/certificates-for-localhost/

要跳过 SSL 测试,您可以使用以下命令:

process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = 0;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM