SockJs - 从安全页面尝试创建不安全的WebSocket连接时出错

3

尝试连接SockJs服务器。我从安全的https页面https://localhost/index.php运行以下代码。

    var sockjs_url = 'http://localhost:9999/echo';
    var sockjs = new SockJS(sockjs_url);

    sockjs.onopen    = function()  {console.log('[*] open' + sockjs.protocol);};
    sockjs.onmessage = function(e) {console.log('[.] message' + e.data);};
    sockjs.onclose   = function()  {console.log('[*] close');};

我收到了 SecurityError: The operation is insecure. 的错误信息,并且它会回退到使用openxhr-polling

如果我从http运行,如http://localhost/index.php,那么websocket连接将建立。

是否不可能从安全页面创建不安全的websocket连接?

更新 在Firefox中出现此问题,但在Chrome中我能够打开websocket连接。

更新2 最终我通过使用https服务器解决了这个问题。 请参见此处。

更新3 相关Firefox Websocket安全问题

1个回答

0

一些浏览器禁止在安全页面中运行不安全的WebSocket连接,包括FireFox。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接