0
点赞
收藏
分享

微信扫一扫

【用websocket的注意了!】https下浏览器只允许使用wss协议,不允许使用ws协议!注意了!


问题描述:

https下发起ws连接,连接失败,浏览器报错。

问题排查:

https连接下浏览器不允许ws协议了,只允许wss协议。

报错内容如下:

VM71 index.js:5 Mixed Content: The page at 'https://10.67.36.75/main.htm?_=1609838620497' was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint 'ws://10.67.36.75:24048/'. This request has been blocked; this endpoint must be available over WSS.

问题解决:

业务(websokcet服务端)新增支持wss协议。

番外番外:

针对web(js)而言,代码无需大改,只需要把websocket的url里的"ws" 改为"wss"即可。。。然而服务端就需要大改来支持wss协议了。。。

经过简单测试,发现chrome浏览器、360安全浏览器等都已经强制https连接下使用wss协议了,ws协议无法使用了。。。看来是大势所趋了。。。

举报

相关推荐

0 条评论