WebSocketException 上的 Flutter Socket io 错误:连接未升级到 websocket

Ali*_*are 8 sockets socket.io dart flutter

我使用这个包,它在测试网站上正常工作,但在应用程序中我得到了这个错误

WebSocketException: Connection to 'https://socket.excopro.com:0/socket.io/?EIO=3&transport=websocket#' was not upgraded to websocket
Run Code Online (Sandbox Code Playgroud)

这是我的代码

SocketService() {
    var socket = io(
        'https://socket.excopro.com:443/', <String, dynamic>{
      'transports': ['websocket'],
      'autoConnect': true,
    });
    socket.on('connect', (_) {
      print('connect');
      socket.emit('msg', 'test');
    });
      socket.on("connecting", (data) => print('connecting'));
      socket.on('connect_error', (data) {
        print(data);
        socket.emit('msg', 'test');
      }); 
  }
Run Code Online (Sandbox Code Playgroud)

小智 5

我遇到了同样的问题。

就我而言,我使用 Nginx 作为代理。我通过在 Nginx 配置中添加一些代理标头解决了该问题。

proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
Run Code Online (Sandbox Code Playgroud)

你可以参考这个链接