I wrote a C# program that uses HttpWebRequest
to connect to an HTTPS site. The GetResponse()
method throws an exception:
SystemError: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
I'm able to connect to the same website using curl.exe --cacert CAFile.pem
. I'd like to be able use the same trusted CA certificates from the C# program.
How can I get HttpWebRequest
to use this CA certificate file (or an X509CertificateCollection
containing certificates parsed from it)?