【问题标题】:Nodejs Fetch API: unable to verify the first certificateNodejs Fetch API:无法验证第一个证书
【发布时间】:2020-10-25 23:58:03
【问题描述】:

我在 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};

任何安全的解决方案最终都会在公共互联网上让我从任何地方访问我的灯吗?

【问题讨论】:

    标签: node.js http fetch philips-hue


    【解决方案1】:

    您似乎尝试使用 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/

    【讨论】:

      【解决方案2】:

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

      process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = 0;

      【讨论】:

        猜你喜欢
        • 2020-03-29
        • 1970-01-01
        • 2015-10-18
        • 2022-07-27
        • 2023-03-17
        • 2021-10-20
        • 2021-01-02
        • 2020-02-17
        • 2021-03-26
        相关资源
        最近更新 更多