【问题标题】:How to pass Authentication Header in Flutter WebSocketChannel?如何在 Flutter WebSocketChannel 中传递 Authentication Header?
【发布时间】:2022-10-21 14:24:42
【问题描述】:

我正在使用颤振web_socket_channel包与服务器通信。 WebSocketChannel 类不采用标头参数。

factory WebSocketChannel.connect(Uri uri, {Iterable<String>? protocols}) =>
      platform.connect(uri, protocols: protocols);

当使用IOWebSocketChannel 传递标头时,我在网络中得到Unsupported operation: Platform._version,就像给定的here 一样。它在 Android 和 iOS 上运行良好。

【问题讨论】:

    标签: flutter dart websocket


    【解决方案1】:

    简洁的答案是:否,因为只能设置 URI 和协议字段中的路径.

    更长的答案: 在纯 JS WebSocket API 中,没有方法可以指定额外的标头供浏览器发送。

    您只能指定

    GET query(was://mysockets.com/path)
    

    和名为Sec-WebSocket-Protocol 的标头协议

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-09-26
      • 2023-03-14
      • 2022-11-12
      • 2022-09-27
      • 1970-01-01
      • 1970-01-01
      • 2020-12-04
      相关资源
      最近更新 更多