nodejs的WebScoket包如何设置UserAgent

harlan
  • 131
connect(): void {
    let cookie = `symphony=${this.token.getSignToken()}`;
    let url =
      "wss://xxx?wsToken=" +
      this.context.globalState.get(STATE_WS_TOKEN);
    let client = new WebSocket.client();
    let headers = {
      cookie: cookie,
      "User-Agent": USER_AGENT
    };
    client.on("connect", (connection: WebSocket.connection) => {
      connection.on("error", (error: Error) => {
        vscode.window.showErrorMessage(error.message);
      });
      connection.on("message", (data: WebSocket.IMessage) => {
        console.log(data);
      });
      connection.on("close", (code, desc) => {
        console.log(code + ":" + desc);
      });
    });
    client.on("connectFailed", (error: Error) => {
      vscode.window.showErrorMessage(error.message);
    });
    client.connect(url, [], "xxx", headers, {
      headers: headers
    });
  }

已知的是上面直接在header里塞入是不好使的

回复
阅读 1.2k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏