1

从客户端连接 SignalR 时遇到问题。我收到此错误“服务器不支持客户端支持的传输。”。它也应该 GET 请求而不是 log 说它是一个 POST 请求。

代码:

final httpConnectionOptions = HttpConnectionOptions(
      /*httpClient: WebSupportingHttpClient(logger,
          httpClientCreateCallback: _httpClientCreateCallback),*/
      logger: logger,
      //logMessageContent: true,
      //transport: HttpTransportType.ServerSentEvents,
      //skipNegotiation: true,
    );
    _hubConnection = HubConnectionBuilder()
        .withUrl(
          _serverUrl + formData,
          options: httpConnectionOptions,
          //transportType: HttpTransportType.ServerSentEvents,
        )
        .withAutomaticReconnect()
        //.withAutomaticReconnect(retryDelays: [2000, 5000, 10000, 20000])
        .configureLogging(logger)
        .build();
    _hubConnection.onclose(({error}) => connectionIsOpen = false);

日志:

I/flutter (31934): Starting HubConnection.
I/chatty  (31934): uid=10154 1.ui identical 11 lines
I/flutter (31934): Starting HubConnection.
I/flutter (31934): Starting connection with transfer format 'TransferFormat.Text'.
I/chatty  (31934): uid=10154(com.ci.radico.radico) 1.ui identical 11 lines
I/flutter (31934): Starting connection with transfer format 'TransferFormat.Text'.
I/flutter (31934): Sending negotiation request: <host>/signalr/negotiate?<data>&negotiateVersion=1
I/chatty  (31934): uid=10154() 1.ui identical 11 lines
I/flutter (31934): Sending negotiation request: <host>/signalr/negotiate?<data>&negotiateVersion=1
I/flutter (31934): HTTP send: url '<host>/signalr/negotiate?<data>&negotiateVersion=1', method: 'POST' content: '' content length = '0' headers: '{ content-type: text/plain;charset=UTF-8 }, { X-Requested-With: FlutterHttpClient }'
I/chatty  (31934): uid=10154(com.ci.radico.radico) 1.ui identical 11 lines
I/flutter (31934): HTTP send: url 'https://ps360ordersapi.ci-private-ase.p.azurewebsites.net/signalr/negotiate?<data>&negotiateVersion=1', method: 'POST' content: '' content length = '0' headers: '{ content-type: text/plain;charset=UTF-8 }, { X-Requested-With: FlutterHttpClient }'
I/flutter (31934): Failed to start the connection: None of the transports supported by the client are supported by the server.
I/chatty  (31934): uid=10154() 1.ui identical 11 lines
I/flutter (31934): Failed to start the connection: None of the transports supported by the client are supported by the server.
I/flutter (31934): HubConnection failed to start successfully because of error 'None of the transports supported by the client are supported by the server.'.
I/chatty  (31934): uid=10154() 1.ui identical 11 lines
I/flutter (31934): HubConnection failed to start successfully because of error 'None of the transports supported by the client are supported by the server.'.
E/flutter (31934): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: None of the transports supported by the client are supported by the server.
E/flutter (31934): 
4

1 回答 1

-1

特别是对于Azure,必须显式启用 Web 套接字。

于 2022-01-28T13:22:02.010 回答