首页 > 解决方案 > Flutter:如何向 websockets sink.add 添加标头

问题描述

大家好,我使用 websocket_channel 库进行颤动,当我连接时,我得到一个 live_id,我将发送到服务器的进一步消息需要该 id,我以这种方式连接到数据库:

channel = New IOWebSocketChannel.connection('ws://host.com/',headers: headers);

假设要断开连接,我需要发送一个 json 正文

{ type: 2, id: 1 }

而且我还需要在标题中传递live_id,我该怎么做?

标签: flutterwebsocket

解决方案


推荐阅读