Custom headers for WebSocket JS

前端 未结 2 2127
遥遥无期
遥遥无期 2021-02-19 06:40

I finding a simple solution to use WebSocket with custom headers for web app based on PHP as backend and js+vuejs as frontend.

My app should connect to WebSocket server

2条回答
  •  执笔经年
    2021-02-19 07:02

    Websocket client API doesn't allow to send custom header, they allow you to set exactly one header, namely Sec-WebSocket-Protocol, i.e. the application specific subprotocol. You could use this header for passing the bearer token.

    Other option is to use token in query string.

    Or you can use some library on client or server which support custom headers implementation eg. https://github.com/crossbario/autobahn-python/tree/master/examples/twisted/websocket/echo_httpheaders

提交回复
热议问题