doghappy / socket.io-client-csharp

socket.io-client implemention for .NET
MIT License
715 stars 124 forks source link

Extra Headers are not taking JSON payloads #345

Open Djurrez opened 7 months ago

Djurrez commented 7 months ago
        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.

doghappy commented 7 months ago

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.