Flutter 使用WebSocket服务报错采坑和解决方案

315 阅读1分钟

先献上我遇到的问题:WebSocketException: Connection to was not upgraded to websocket 网上查了一圈,也试着其他人贡献的解决办法.包括修改ngix配置

location /wsapp/ { proxy_pass http://wsbackend; proxy_http_version 1.1; proxy_set_header Upgrade httpupgrade;proxysetheaderConnection"Upgrade";proxysetheaderHosthttp_upgrade; proxy_set_header Connection "Upgrade"; proxy_set_header Host host; }

1704967907210.jpg

出现上面的错误,是因为websocket请求的url不是websocket的协议的.可以先在线测一下.