socket.io-client-csharp icon indicating copy to clipboard operation
socket.io-client-csharp copied to clipboard

Extra Headers are not taking JSON payloads

Open Djurrez opened this issue 1 year ago • 1 comments

        public void Initialize()
        {
            var client = new SocketIOClient.SocketIO("http://mywebsocket", new SocketIOOptions
            {
                ExtraHeaders = new Dictionary<string, string>
                {
                    {"Authorization", "{\"id\":123, \"first_name\":\"A\", \"last_name\":\"A\", \"username\":\"A\", \"auth_date\":123, \"hash\":\"gjsdkgbskjdgbkasjdbgjkasbdjgkasdgbjkasbdkagjk\"}"},
                    {"SessionID", "test" }
                }
            });

            client.ConnectAsync().Wait();

        }

Seems like ExtraHeaders are not taking any stringified JSON data. Once you do this it stops sending out any requests.

Djurrez avatar Dec 12 '23 21:12 Djurrez

the reason is that the header "Authorization" is a special header. when you try to add it, .NET will try to validate value first. Sure the value you provided is invalid.

the issue same as https://github.com/doghappy/socket.io-client-csharp/issues/300

so how to solve it?

  1. try to use another header name
  2. allow "authorization" header. https://github.com/doghappy/socket.io-client-csharp/blob/956d919dee578ae385597b8427278ae2c454de41/src/SocketIOClient/Transport/Http/DefaultHttpClient.cs#L21-L24

for option2, actually I have implemented but I need to do some research.

doghappy avatar Dec 14 '23 08:12 doghappy