Have you ever received that error
The remote certificate is invalid according to the validation procedure
when attempting to communicate via https to a server? When y0u browse the server in a browser, you probably get a warning which you can bypass, but how do you do it in code?
Simple, before you attempt to open the webrequest, set the ServerCertificateValidationCallback on the ServicePointManager to be handled by a custom function, which accepts your certificate. An example is shown below
ServicePointManager.ServerCertificateValidationCallback = New Net.Security.RemoteCertificateValidationCallback(AddressOf(ValidateCertificate)
This sets up the initial callback to point at a function ValidateCertificate, the code for this is shown below
Private Function ValidateCertificate(ByVal sender As Object, ByVal certificate As X509Certificate, ByVal chain As X509Chain, ByVal sslPolicyErrors As Net.Security.SslPolicyErrors) As Boolean
‘Return True to force the certificate to be accepted, nb this accepts any certificate.
Return True
End Function
And yes, I know the example is in VB.NET, I’m being hampered in my current contract by using it!