本文介绍了带有 SSL 的 WebSocket的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以使用带有 HTTPS 的 WebSockets?
Is it possible to have WebSockets with HTTPS?
切换到 HTTPS 时,我的 WebSocket 返回一个安全错误并且与常规 HTTP 完美配合.
When switching to HTTPS, my WebSocket returns a security error and works perfectly with regular HTTP.
下面是一个片段;
socket = new WebSocket("ws://my_www:1235");
推荐答案
WebSocket 连接从 HTTP 或 HTTPS 握手开始.通过 HTTP 访问页面时,可以使用 WS 或 WSS (WebSocket secure: WS over TLS).但是,当您的页面通过 HTTPS 加载时,您只能使用 WSS - 浏览器不允许降级"安全性.
The WebSocket connection starts its life with an HTTP or HTTPS handshake. When the page is accessed through HTTP, you can use WS or WSS (WebSocket secure: WS over TLS) . However, when your page is loaded through HTTPS, you can only use WSS - browsers don't allow to "downgrade" security.
这篇关于带有 SSL 的 WebSocket的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!