When accessing HTTPS content, sometimes you often see a certificate error (not in the operating system's certificate trust chain?). ) prompt, in the browser we can ignore the wrong certificate, continue to access the content of the Web page.
However, in a. NET program, it is up to the code to determine whether to ignore the wrong certificate.
Solution:
Before you arbitrarily access the program code for HTTPS content, set up a certificate handler with the following code:
Servicepointmanager.servercertificatevalidationcallback = (sender, cert, chain, error) == { Returntrue;};
This is because it is a static type method, so only need to add once, but also note that this is the application of global certificate processing, if you want to do different certificate processing in different places, please note.
Here, for the sake of convenience, return true directly, representing acceptance of the certificate, whether right or wrong. If the scenario requires rigor, you should carefully determine if the certificate is correct, and then return the result.
An error occurred while remotely requesting HTTPS content in. NET: The remote certificate is not valid according to the authentication process.