尝试连接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安全问题