Closed arun5068 closed 2 years ago
could you try it?
var clientTest = new SocketIO("https://livestream.icicidirect.com", new SocketIOOptions
{
Auth = new
{
user = UserID_Session,
token = Session_Token_64
},
Transport = SocketIOClient.Transport.TransportProtocol.WebSocket
}) ;
var ExtraHeaders = new Dictionary<string, string>
{
{ "User-Agent", "abcdss" }
};
clientTest.Options.ExtraHeaders = ExtraHeaders;
Well your library is a great work, I tried with .NETCore and .NETFramework both and here are my observations.
for .NETCore no problem but as my server is using Socket.io2x, i had to change the serialization to newtonsoft json to work properly.
for .NETFramework I have to use reflection to remove IsRequestRestricted from headerInfo hash table
here is the code for that
// use reflection to remove IsRequestRestricted from headerInfo hash table Assembly a = typeof(HttpWebRequest).Assembly; foreach (FieldInfo f in a.GetType("System.Net.HeaderInfoTable").GetFields(BindingFlags.NonPublic | BindingFlags.Static)) { if (f.Name == "HeaderHashTable") { Hashtable hashTable = f.GetValue(null) as Hashtable; foreach (string sKey in hashTable.Keys) {
object headerInfo = hashTable[sKey];
//Console.WriteLine(String.Format("{0}: {1}", sKey,
hashTable[sKey])); foreach (FieldInfo g in a.GetType("System.Net.HeaderInfo").GetFields(BindingFlags.NonPublic | BindingFlags.Instance)) {
if (g.Name == "IsRequestRestricted")
{
bool b = (bool)g.GetValue(headerInfo);
if (b)
{
// string name =
headerInfo.GetValue().Name; if (sKey == "User-Agent") { g.SetValue(headerInfo, false); //Console.WriteLine(sKey + "." + g.Name + " changed to false"); } }
}
}
}
}
}
now it is working, though few issues are there related with disconnection but even in postman also i have seen disconnection problem.
Again great work man Cheers
https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail Virus-free. www.avast.com https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
On Sun, Jul 17, 2022 at 3:06 PM HeroWong @.***> wrote:
could you try it?
var clientTest = new SocketIO("https://livestream.icicidirect.com", new SocketIOOptions { Auth = new { user = UserID_Session, token = Session_Token_64 }, Transport = SocketIOClient.Transport.TransportProtocol.WebSocket }) ; var ExtraHeaders = new Dictionary<string, string> { { "User-Agent", "abcdss" } };clientTest.Options.ExtraHeaders = ExtraHeaders;
— Reply to this email directly, view it on GitHub https://github.com/doghappy/socket.io-client-csharp/issues/286#issuecomment-1186460003, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWZKH5CBRMNS4EYW7KDFGSLVUPHZJANCNFSM53UBWFOA . You are receiving this because you authored the thread.Message ID: @.***>
I am trying to connect to https sever with latest version but could not get connected, The same server is working with the python socketio library .
Here is my C# Code
Here is python code
Tried with different EIO options also but no success. User-agent header is required otherwise server is not responding. Is there anyway to set User-Agent header or I have to modify original source code as suggested by https://stackoverflow.com/questions/22635663/setting-user-agent-http-header-in-clientwebsocket?