javascript 网络错误 12152:Edge 和 IE 11 中的 WebSockets

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33080095/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 16:05:53  来源:igfitidea点击:

Network Error 12152: WebSockets in Edge and IE 11

javascriptinternet-explorerwebsocketmicrosoft-edge

提问by SammyG

I have a site using websockets secure (WSS) and works very well in chrome.

我有一个使用 websockets secure (WSS) 的站点,并且在 chrome 中运行良好。

Testing in IE and Edge also works however in the browser console I get Network Error 12152which will also trigger the websocket.addEventListener("error",function(){})if implemented.

在 IE 和 Edge 中的测试也可以在我得到的浏览器控制台中运行Network Error 12152,这也会触发websocket.addEventListener("error",function(){})if 实现。

Everything actually works I just get this error which doesnt seem to break anything.

一切实际上都有效,我只是收到这个似乎没有破坏任何东西的错误。

Error is triggered When socket is closed from Browser Side

从浏览器端关闭套接字时触发错误

Headers in EDGEenter image description here

EDGE 中的标题在此处输入图片说明

More Info: Example of the code I use

更多信息:我使用的代码示例

//connect via wss then
ws.addEventListener("error",function(event){ // this hits when Socket is closed})
ws.addEventListener("open",function(){
       ws.addEventListener("message",function(event){
        //do stuff
        ws.Close()
       })
})

To Confirm the problem further

进一步确认问题

I went to https://www.websocket.org/echo.htmlin edge the site which has the ability to test websocket connections. I made it connect to my server. which opens the connection without a problem. However in just the same way I have been getting problems with my code. This site also throws an error when I click the disconnect button. See Image Below. Is this a bug in IE/Edge? enter image description here

我在该站点的边缘访问了https://www.websocket.org/echo.html,该站点能够测试 websocket 连接。我让它连接到我的服务器。这可以毫无问题地打开连接。然而,以同样的方式,我的代码出现问题。当我单击断开连接按钮时,该站点也会引发错误。见下图。这是 IE/Edge 中的错误吗? 在此处输入图片说明

My Server isnt disconnecting correctly?I use the above site with the default destination (Their websocket server) and not mine. There are no errors. But when connecting to mine on disconnect there are errors.

我的服务器没有正确断开连接?我将上述站点与默认目标(他们的 websocket 服务器)一起使用,而不是我的。没有错误。但是在断开连接时连接到我的时会出现错误。

What could be the problem?

可能是什么问题呢?

Thanks

谢谢

回答by Tschallacka

Looking at the Microsoft KB article you are not givng back the expected response/headers on connection setup

查看 Microsoft KB 文章,您没有在连接设置时返回预期的响应/标头

From the microsoft knowledge base

来自微软知识库

12152 ERROR_HTTP_INVALID_SERVER_RESPONSE

The server response could not be parsed.

12152 ERROR_HTTP_INVALID_SERVER_RESPONSE

无法解析服务器响应。

From the developper docs of mozillaif you look at the Server Handshake Responsepart

如果您查看服务器握手响应部分,则来自mozilla开发人员文档

When it gets this request, the server should send a pretty odd-looking (but still HTTP) response that looks like this (remember each header ends with \r\n and put an extra \r\n after the last one):

HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=

当它收到这个请求时,服务器应该发送一个看起来很奇怪(但仍然是 HTTP)的响应,看起来像这样(记住每个标头都以 \r\n 结尾,并在最后一个标头后面放一个额外的 \r\n):

HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=

So, I suggest you check your headers and see which responses you are sending on the handshake, so you keep in line with protocols.

因此,我建议您检查您的标头,看看您在握手时发送了哪些响应,以便与协议保持一致。

回答by Habou Med

I have fixed the same error in IE browsers. Check the capitalization of the first letter of websocket.

我在 IE 浏览器中修复了相同的错误。检查 websocket 的第一个字母的大小写。

  • Non IE browser:

    Upgrade: **w**ebsocket

  • IE browser:

    Upgrade: **W**ebsocket

  • 非 IE 浏览器:

    Upgrade: **w**ebsocket

  • IE浏览器:

    Upgrade: **W**ebsocket