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

后端 未结 5 1424
春和景丽
春和景丽 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:08

    This information has been deprecated since socket.io 1.0

    There are two methods of authorization: global or namespace (think route). The global method is set on the server with the io.set('authorization', function (handshakeData, callback) configuration call.

    The handshakeData object contains the following information:

    {
       headers: req.headers       //  the headers of the request
     , time: (new Date) +''       //  date time of the connection
     , address: socket.address()  //  remoteAddress and remotePort object
     , xdomain: !!headers.origin  //  was it a cross domain request?
     , secure: socket.secure      //  https connection
     , issued: +date              //  EPOCH of when the handshake was created
     , url: request.url          //  the entrance path of the request
     , query: data.query          //  the result of url.parse().query or a empty object
    }
    
    
    

    The above information and a deeper explanation is available on this documentation page.

    提交回复
    热议问题