gpt4 book ai didi

javascript - 建立 websocket 连接时出错

转载 作者:行者123 更新时间:2023-12-01 17:24:19 26 4
gpt4 key购买 nike

我正在使用 ws npm 在服务器端,websocket 在客户端。

从 node-js 运行此代码时它工作正常,但从浏览器运行它会出现以下错误:

failed: Error in connection establishment: net::ERR_CERT_COMMON_NAME_INVALID


const ws = new WebSocket('wss://domain:port', null, { 
rejectUnauthorized: false
});

ws.onerror = function (e) {
console.log(e)
}

ws.onclose = function (e) {
console.log(e)
}

ws.onopen = function () {
console.log('connected ')
ws.send(JSON.stringify({ msg: 'msg' }));
}

最佳答案

net::ERR_CERT_COMMON_NAME_INVALID这看起来是一个证书问题。浏览器使用各种证书。例如。您可以在 中查看 Mozilla Firefox 中的证书首选项 > 隐私和安全 > 证书 ,您可以探索导致问题的证书。

确保您的 API 指向正确的证书

关于javascript - 建立 websocket 连接时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54542636/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com