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

后端 未结 5 2022
遇见更好的自我
遇见更好的自我 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:17

    Try this:
    What you would want to do is, to install the certificate into your local machine.

    The procedure if it was not in code would be to do the following:

    1. Open Internet Explorer in Administrator mode (not Chrome).
    2. Go to the site
    3. Select proceed
    4. Click the titelbar / url bar on the certificate, to view the certificate.
    5. Click install certificate.

    So you can try to have a look at these other questions and see if they help you:

    • How can I install a certificate into the local machine store programmatically using c#?
    • Install certificates in to the Windows Local user certificate store in C#

    Try to install the certificate and see if you go to the url again, if it asks to proceed.

    ****EDIT**:
    I read the site certificate, it is because there is a mismatch between the certificate and the site's url.

    A simple change would be this:

    htmlCode = wc.DownloadString("https://oig.hhs.gov/exclusions/exclusions_list.asp");
    

    Just remove the www.

提交回复
热议问题