sta / websocket-sharp

A C# implementation of the WebSocket protocol client and server
http://sta.github.io/websocket-sharp
MIT License
5.74k stars 1.66k forks source link

How is it possible to add headers to my WebSocket #710

Closed FabioGaming closed 9 months ago

FabioGaming commented 2 years ago

My WebSocket requires headers, how can I add them? The default Socket Handling does it like this: Socket.Options.SetRequestHeader("key", "value");

JungleeNitish commented 11 months ago

yes as many as you like, just go to createHandshakeRequest() method and add required headers there // As client private HttpRequest createHandshakeRequest() { var ret = HttpRequest.CreateWebSocketRequest(_uri);

        var headers = ret.Headers;

            headers["customHeaderOne"] = "test Header";
            headers["customHeaderTwo"] = 2;

        if (!_origin.IsNullOrEmpty())
            headers["Origin"] = _origin;