Kartik Rokde
Kartik Rokde

Reputation: 3913

Sending custom headers in websocket handshake

How to send custom headers in the first handshake that occurs in the WebSocket protocol?

I want to use custom header in my initial request "**X-Abc-Def : xxxxx"

WebSocket clients are Python & Android client.

Upvotes: 3

Views: 12068

Answers (2)

ThiefMaster
ThiefMaster

Reputation: 318488

In the python websocket-client you can indeed pass custom headers easily - there's a keyword argument header available for this; see the following example from the docs:

conn = create_connection("ws://echo.websocket.org/", header={"User-Agent": "MyProgram"})

Edit: Keyword should be header, not headers.

Upvotes: 9

Parag Datar
Parag Datar

Reputation: 59

@ThiefMaster got it perfect. But if you want to add custom headers, you can do that with the argument header instead of headers. Hope this helps

Upvotes: 3

Related Questions