微信小程序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”请求头但是响应中没有此字段
这个,在后端握手时设置一下请求头(Sec-WebSocket-Protocol)即可,前端发来什么值,这里就写什么值
测试:
在Chrome控制台输入 var ws = new WebSocket("ws:xx.xx.com","chat"),chat就是Sec-WebSocket-Protocol的值,协议名
2018年10月24日补充:
——《HTML5 WebSocket权威指南》