简体   繁体   English

WebSocket在Internet Explorer下关闭-错误代码1006

[英]WebSocket closes under Internet Explorer - error code 1006

My WebSocket implementation works correctly in Chrome and Firefox. 我的WebSocket实现可在Chrome和Firefox中正常运行。

In IE11 I get this error: 在IE11中,我收到此错误:

Websocket Error: Network Error 12152, The server returned an invalid or unrecognized response Websocket错误:网络错误12152,服务器返回了无效或无法识别的响应

I use js WebSocket class and reactPhp and https://github.com/ratchetphp/RFC6455 for backend. 我使用js WebSocket类和reactPhp和https://github.com/ratchetphp/RFC6455作为后端。

This is the request-response data under IE. 这是IE下的请求-响应数据。 It looks ok to me. 在我看来还可以。 在此处输入图片说明

I checked that Websocket returns code 1006 and empty reason. 我检查了Websocket是否返回代码1006和空原因。

How can I fix the IE11 error? 如何解决IE11错误?


The problem was that in response headers I should return only one protocol in Sec-WebSocket-Protocols. 问题在于,在响应标头中,我应该仅在Sec-WebSocket-Protocols中返回一个协议。

Why it doesn't work only under IE - because I split the protocols in backend by comma+space but IE return the protocols without space only with comma separator. 为什么它仅在IE下不起作用-因为我在后端用逗号+空格分割了协议,但是IE仅使用逗号分隔符返回了不带空格的协议。 The other browsers return the protocols with comma+space. 其他浏览器以逗号+空格返回协议。

For example the code right in backend it looks like that: 例如,后端的代码如下所示:

array_map('trim', explode(',', $this->headers['Sec-WebSocket-Protocol'])); array_map('trim',explode(',',$ this-> headers ['Sec-WebSocket-Protocol'])));

The problem was that in response headers I should return only one protocol in Sec-WebSocket-Protocols. 问题在于,在响应标头中,我应该仅在Sec-WebSocket-Protocols中返回一个协议。

Why it doesn't work only under IE - because I split the protocols in backend by comma+space but IE return the protocols without space only with comma separator. 为什么它仅在IE下不起作用-因为我在后端用逗号+空格分割了协议,但是IE仅使用逗号分隔符返回了不带空格的协议。 The other browsers return the protocols with comma+space. 其他浏览器以逗号+空格返回协议。

For example the code right in backend it looks like that: 例如,后端的代码如下所示:

array_map('trim', explode(',', $this->headers['Sec-WebSocket-Protocol']));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM