没有 SSL 的 Chrome 上的 WebSocket 连接失败 [英] WebSocket connection fails on Chrome without SSL

查看:92
本文介绍了没有 SSL 的 Chrome 上的 WebSocket 连接失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在标准网页和 Tomcat v7.0.62 服务器之间设置 WebSocket.在 Firefox、Edge 和 IE11 上打开/关闭 Tomcat SSL 时,连接工作正常.但是,在 Chrome (v66.03) 中,仅当我在服务器上打开 SSL 并通过 https 连接时,websocket 才会连接.在 Chrome 中,当我在服务器上关闭 SSL 并尝试通过 http 连接时,它会引发错误.

I'm setting up a WebSocket between a standard web page and a Tomcat v7.0.62 server. The connection works fine with Tomcat SSL turned on/off on Firefox, Edge and IE11. However, in Chrome (v66.03), the websocket only connects when I've turned on SSL on the server and connect via https. In Chrome, when I turn SSL off on the server and try to connect via http, it throws an error.

这是 Chrome 在 Tomcat 上关闭 SSL 的情况下尝试通过 http 连接时抛出的错误...

Here's the error Chrome throws when trying to connect via http with SSL turned off on Tomcat...

Error in connection establishment: net::ERR_PROXY_AUTH_REQUESTED_WITH_NO_CONNECTION

这是我在客户端上的 WebSocket 连接代码...

Here's my WebSocket connection code on the client...

var wss = "wss://";
if (document.location.protocol === "http:") {
   wss = "ws://";
}
var wsURL = wss + document.location.host + "/status?sessionId=<%=session.getId()%>";

这是 Chrome 特有的,需要在非 https websocket 连接上使用特殊代码吗?

Is this something Chrome specific that needs special code on non-https websocket connections?

推荐答案

这是 Chrome 特定的行为.Chrome 不允许不安全的 websocket (ws) 连接到本地主机(只有 wss,所以你应该为你的本地 web/websocket 服务器设置一个 TLS 证书).但是在 Firefox 和其他浏览器中同样应该可以正常工作.

This is a Chrome specific behavior. Chrome doesn't allow unsecure websocket (ws) connections to localhost (only wss, so you should setup a TLS certificate for your local web/websocket server). But the same should work without any issues in Firefox and other browsers.

有关此问题,请参阅 Chromium 上的 Chrome 错误报告.这个特殊的问题是故意的,他们已经做出了这个改变通过防止对在本地主机上侦听的内部网络设备和进程的攻击,Chrome 更加安全.

Please refer the Chrome bug report on Chromium regarding this issue. This particular problem is intentional, and they have made this change to make Chrome more secure by preventing attacks against internal network devices and processes listening on localhost.

https://bugs.chromium.org/p/chromium/问题/详细信息?id=378566

这篇关于没有 SSL 的 Chrome 上的 WebSocket 连接失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆