连接ws 时报错 ,麻烦帮看看,提前谢谢了,昨天还执行成功了,为什么连初始化都报错

gaoyongguang

后台连接是ws://xxxxxxx.cn:8282/

执行连接 var ws = new WebSocket('ws://xxxxxx.cn:8282');
ws.onmessage = function (e) {
console.log(e);
}
报错 Mixed Content: The page at 'https://www.baidu.com/' was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint 'ws://xxxxxxx.cn:8282/'. This request has been blocked; this endpoint must be available over WSS.

Uncaught DOMException: Failed to construct 'WebSocket': An insecure WebSocket connection may not be initiated from a page loaded over HTTPS.
at <anonymous>:1:14

后来改成
var ws = new WebSocket('wss://xxxxxxx.cn:8282');
ws.onmessage = function (e) {
console.log(e);
}
这倒好直接报
VM62:1 WebSocket connection to 'wss://xxxxxxxx:8282/' failed:

2877 1 0
1个回答

jackyxie

https页面不能访问ws连接。要配置成wss

  • 暂无评论
年代过于久远,无法发表回答
🔝