socket.io-client how to set request header when making connection

后端 未结 5 1395
春和景丽
春和景丽 2020-12-24 05:16

I\'m trying to set a http header when socket.io client makes the connection request. Is there a way to do this?

Here is what i\'m doing:

// server si         


        
5条回答
  •  囚心锁ツ
    2020-12-24 06:10

    You can use extraHeaders option, if you are using socket.io-client >= 1.4.

    For example:

    var socket = io("http://localhost", {
      extraHeaders: {
        Authorization: "Bearer authorization_token_here"
      }
    });
    

    engine.io-client, which is a backend of socket.io-client, introduced extraHeaders support on 2015-11-28.

提交回复
热议问题