微信小程序WebSocket报错:Error during WebSocket handshake: Sent non-empty \'Sec-WebSocket-Protocol\' header but no response was received

Error during WebSocket handshake: Sent non-empty \'Sec-WebSocket-Protocol\' header but no response was received

WebSocket握手阶段出错:发送了非空“Sec-WebSocket-Protocol”请求头但是响应中没有此字段

微信小程序WebSocket报错:Error during WebSocket handshake: Sent non-empty \'Sec-WebSocket-Protocol\' header but no response was received

 

这个,在后端握手时设置一下请求头(Sec-WebSocket-Protocol)即可,前端发来什么值,这里就写什么值

 

微信小程序WebSocket报错:Error during WebSocket handshake: Sent non-empty \'Sec-WebSocket-Protocol\' header but no response was received

 

测试:

在Chrome控制台输入 var ws = new WebSocket("ws:xx.xx.com","chat"),chat就是Sec-WebSocket-Protocol的值,协议名

2018年10月24日补充:

微信小程序WebSocket报错:Error during WebSocket handshake: Sent non-empty \'Sec-WebSocket-Protocol\' header but no response was received

微信小程序WebSocket报错:Error during WebSocket handshake: Sent non-empty \'Sec-WebSocket-Protocol\' header but no response was received

                                     ——《HTML5 WebSocket权威指南》

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zgggzy.html