Closed useraccessdenied closed 1 year ago
I think I have pinpointed the issue.
The issue is with this line.
ExtraHeaders = new Dictionary<string, string> { { "User-Agent", "dotnet-socketio[client]/socket" } }
and specifically with the key User-Agent
.
For whatever reasons, either a bug in dotnet framework 4.x or something other, my program loops infinitely on header key User-Agent
. It works flawlessly on UserAgent
, User_Agent
and User--Agent
. There seems to be some kind of parsing issue within dotnet framework and User-Agent
key is clashing with something in there.
Reason: Some common headers are considered restricted and are either exposed directly by the API (such as User-Agent) or protected by the system and cannot be changed.
here is a good solution: https://stackoverflow.com/a/15976436/7771913
I will fix the issue
failed to hack AddWithoutValidate
via reflection, ConnectAsync
will throw same exception.
Looks like this is a bug in .NET Framework https://github.com/dotnet/corefx/issues/26627#issuecomment-391472613
How about this solution? (StackOverflow.com) Modify HeaderInfoTable with reflection
Here, read-only IsRequestRestricted
is modified using reflection to false and then it won't throw error on setting property as usual. This will work for both ClientWebSocket
and HTTPWebRequest
.
Yeah, I am tested, it works
Good to hear!
fixed
Thanks for the effort!
One more thing. Issue #290 seems to be the same as this. The user also sets User-Agent
there and he might not know it was due to .net framework 4.x.
Hi @doghappy,
I found an issue with this library when used with .NET framework 4.x series (tested on 4.6 - 4.8). The
ConnectAsync
function seems to be stuck in an infinite loop when I passExtraHeaders
toSocketIO
constructor options. The client does not even seem to initiate handshake to the server. WithoutExtraHeaders
inSocketIOOptions
, theConnectAsync
function establishes a connection to the server as expected. None of theSocketIO
events are triggered on client and server side when supplyingExtraHeaders
. I am unable to debug where the code is stuck as debugger does not seem to provide any useful information.This issue seems to be affected in .NET Framework 4.x series only. The below code works without any change in .net6.0 and others.
Here is my client code
And here is the server code that I used to test it.
My project file