Closed bhemala closed 2 years ago
Is it possible to ignore these two options?
If I ignore them and try to connect to SSL with selfsigned certificate I get this excepations:
System.Security.Authentication.AuthenticationException HResult=0x80131501 Message=The remote certificate is invalid according to the validation procedure: RemoteCertificateNameMismatch, RemoteCertificateChainErrors Source=System.Private.CoreLib StackTrace: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
I tried:
HttpClientHandler httpClientHandler = new HttpClientHandler();
httpClientHandler.ServerCertificateCustomValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;
client.HttpClient = new HttpClient(httpClientHandler);
But it does not helped.
pls try:
var client = new SocketIO("http://localhost:11000/");
client.ClientWebSocketProvider = () =>
{
var clientWebSocket = new DefaultClientWebSocket
{
ConfigOptions = o =>
{
var options = o as ClientWebSocketOptions;
options.RemoteCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) =>
{
Console.WriteLine("SslPolicyErrors: " + sslPolicyErrors);
return true;
};
}
};
return clientWebSocket;
};
It works! thanks
Hi,
I have portated my app from .NET Core to .NET Framework 4.7.2 and I am not able to set:
options.RemoteCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => { Console.WriteLine("SslPolicyErrors: " + sslPolicyErrors); return true; };
Method RemoteCertificateValidationCallback does not exists in:
`#region Assembly System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 // C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.7.2\System.dll
using System.Security.Cryptography.X509Certificates;
namespace System.Net.WebSockets { // // Summary: // Options to use with a System.Net.WebSockets.ClientWebSocket object. public sealed class ClientWebSocketOptions { ............. }`
How can I use it in .NET Framework?
Thanks
For .NET Framework please use the following code instead
System.Net.ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) =>
{
Console.WriteLine(sslPolicyErrors);
// Note it will ignore all SSL errors
return true;
};
Excellent, it works. Thanks!
Hi @bhemala , may I have similar issue with yours. I tried to run your code but I have this error instead @doghappy .
'SocketIO' does not contain a definition for 'ClientWebSocketProvider' and no accessible extension method 'ClientWebSocketProvide' accepting a first argument of type 'SocketIO' could be found (are you missing a using directive or an assembly reference?)
May I know which SocketIOClient.NetFx version you use right now? I currently use the latest version: 2.0.2.10
Hi @sitihawasabri, for .NET Framework I do not use client.ClientWebSocketProvider. I skipped this part and use System.Net.ServicePointManager.ServerCertificateValidationCallback instead.
var client = new SocketIO("http://localhost:11000/");
System.Net.ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) =>
{
Console.WriteLine(sslPolicyErrors);
// Note it will ignore all SSL errors
return true;
};
Okay noted, thank you so much!
Hi, how can I connect to socket.IO with SSL and selfsigned certificate? In JS code I use this:
In csharp I do not know how to add rejectUnauthorized and secure true.
Thanks