簡體   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