Friday, 13 January 2017

cIgnore SSL HTTPS errors GetAsync Httplient .Net winforms

I'm working on a Windows app at the moment and part of the job involves comms with a Rest api over https. During the development phase the SSL certs for the server aren't valid, and this causes GetAsync for the HttpClient to return a Taskstatus.Faulted, and the whole thing breaks. To overcome this you just need this line of code:

ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;