在用vue连接websocket时候报Response must not include ‘Sec-WebSocket-Protocol’ header if not present in request: websocket错误
代码如下:
this.websock = new WebSocket(url);
解决办法,在 new WebSocket(url)的时候加上protcol参数
原本的声明方法为:var Socket = new WebSocket(url, [protocol] );
将代码改为下面参数
this.websock = new WebSocket(url, 'websocket');
再次运行,错误消失;
Response must not include ‘Sec-WebSocket-Protocol’ header if not present in request: websocket
以此类推:如果上面红色代码为chat,则为new WebSocket(wsuri, 'chat');
如果上面红色代码为superchat,则为new WebSocket(wsuri, 'superchat');