Microsoft Edge不允许WebSocket进行本地主机回送 [英] Microsoft Edge does not allow localhost loopback for websockets
问题描述
我有网站和桌面应用程序,我想通过websockets连接它们.因此,例如,我的网站尝试连接到wss://localhost:8080.
I have web-site and desktop application, and I want to connect them by websockets. So my web-site tries to connect to wss://localhost:8080, for example.
它在IE11中有效,但在"MS Edge"中却出现错误:
It works in IE11, but in "MS Edge" I have an error:
不允许跨区域请求
Cross zone request is not allowed
我在Win10 10240上遇到此问题,因此默认情况下启用了允许本地主机回送"标志,并且它没有帮助.
I have this problem on Win10 10240, so the flag "Allow localhost loopback" is enabled by default, and it did not help.
当我使用CheckNetIsolation LoopbackExempt -a -n="Microsoft.MicrosoftEdge_8wekyb3d8bbwe"
或
When I use CheckNetIsolation LoopbackExempt -a -n="Microsoft.MicrosoftEdge_8wekyb3d8bbwe"
or this utility, all works as expected.
那么,是这种情况吗,在新版本的"MS Edge"中,http允许环回,而websocket不允许环回? 如果是这样,是否有可能采取一些解决方法,而不是强迫我的用户运行一些Shell命令或下载externall实用程序?
So, is this a case, that in new builds of "MS Edge" loopbacks are allowed for http, but not allowed for websockets? And if so, is it possible to make some workaround, and not to force my users to run some shell comand or to download externall utility?
相关问题:可以'在Windows 10预览版的Microsoft Edge(Project Spartan)中打开localhost
推荐答案
经过一番研究,我发现了错误的根源.这是我的代码库,用于重现错误: https://github.com/AZaviruha/ms- edge-ws-strange
After some research I found the source of error. Here is my repo, to reproduce error: https://github.com/AZaviruha/ms-edge-ws-strange
简而言之,当在MS Edge中调用new WebSocket
时,如果使用错误的本地"-主机参数调用它,则不会生成异常:
In short, when you call new WebSocket
in MS Edge, it does not generate exception, when you call it with wrong "local"-host argument:
var socket, path;
var hosts = ['localhost', '127.0.0.1'];
for (var i in hosts) {
path = 'ws://'+hosts[i]+':9446';
console.log( '===> Tested path :: ', path );
try {
socket = new WebSocket( path );
break;
}
catch ( e ) {
// !!! Never shown !!!
console.error( '===> WebSocket creation error :: ', e );
}
}
因此,您无法重试"与其他主机连接.
Because of this, you can't "retry" to connect with different hosts.
顺便说一句,如果您尝试非本地不存在的主机,它将生成异常!
By the way, if you try non-local non-existent host, it will generate exception!
这篇关于Microsoft Edge不允许WebSocket进行本地主机回送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!