简体   繁体   中英

WebSocket closes under Internet Explorer - error code 1006

My WebSocket implementation works correctly in Chrome and Firefox.

In IE11 I get this error:

Websocket Error: Network Error 12152, The server returned an invalid or unrecognized response

I use js WebSocket class and reactPhp and https://github.com/ratchetphp/RFC6455 for backend.

This is the request-response data under IE. It looks ok to me. 在此处输入图片说明

I checked that Websocket returns code 1006 and empty reason.

How can I fix the IE11 error?


The problem was that in response headers I should return only one protocol in 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. 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']));

The problem was that in response headers I should return only one protocol in 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. 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']));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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