Web Client Exception: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel

后端 未结 5 2020
遇见更好的自我
遇见更好的自我 2021-02-05 05:35

I have a simple app that uses the C# Web Client class to download a websites HTML. This is a stripped down sample of the code I\'m using:

WebClient wc = new Web         


        
5条回答
  •  名媛妹妹
    2021-02-05 06:19

    As far as I know this is because they use a invalid or expired SSL certificate. You can bypass (ignore) it by using:

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

    Edit 2015:

    This post is getting a lot of upvotes, but I regret my answer. It may remove your error, but it won't fix the issue. Accepting any SSL certificates will leave you vulnerable for man in the middle attacks, so it's generally a very bad idea. I will leave this answer for future reference, but please take note that you should try to fix the issue at the root, namely by making sure the SSL certificate is valid.

提交回复
热议问题