建立网络套接字连接时出错

问题描述 投票:1回答:1

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

当从节点js运行此代码时,它工作正常,但从浏览器运行时会出现以下错误失败:建立连接错误: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' }));
}

`

javascript websocket wss
1个回答
0
投票
net::ERR_CERT_COMMON_NAME_INVALID,这似乎是证书问题。浏览器使用各种证书。例如。您可以在

首选项>隐私和安全性>证书中查看Mozilla Firefox中的证书,并可以探究是哪个证书导致了您的问题。

确保您的API指向正确的证书
© www.soinside.com 2019 - 2024. All rights reserved.