websocket-client
websocket-client copied to clipboard
Ignore SSL errors caused by self signed certificate
I am unable to connect to a websocket based API running locally as it uses a self signed certificate. How can i disable certificate validation?
Disabling SSL validation is done globally in .NET and not specific to websocket client. See: https://stackoverflow.com/questions/38138952/bypass-invalid-ssl-certificate-in-net-core
I'm using .NET framework, not .NET core
The same approach, they brought it back to .NET core for backward compatibility.
I'm not sure why youre pointing me to that post, ServicePointManager.ServerCertificateValidationCallback
has no effect on this, and ServerCertificateCustomValidationCallback
requires a http handler
Then, unfortunately, cannot help you, I used ServicePointManager.ServerCertificateValidationCallback
sometime in the past and it worked.
It seems they added a new API for this in version 2.1 of netstandard (which is not covered by .NET Framework). https://social.msdn.microsoft.com/Forums/vstudio/en-US/8fb8dc56-580e-42a0-a89d-706f2d1417aa/add-remotecertificatevalidationcallback-to-clientwebsocket?forum=netfxbcl
_ws = new System.Net.WebSockets.ClientWebSocket();
// Please do not use in production environment
_ws.Options.RemoteCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;
If you are using .NET Framework, add this line at some point before attempting connection:
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => { return true; };