C# WebClient Download String https

前端 未结 2 1624
-上瘾入骨i
-上瘾入骨i 2021-01-13 01:49

In the webbrowser I can normally load the following url: https://security.ultimatxxxx.com:443/Serverstatus.ashx

When I do it with:

Webc         


        
相关标签:
2条回答
  • 2021-01-13 02:17

    If you just wish to accept all certificates, you'll need to set certificate check, before you make your request:

    ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
    

    This will accept all certificates.

    Although - if you need to actually check the certificate do something like:

    ServicePointManager.ServerCertificateValidationCallback =
        (sender, certificate, chain, sslPolicyErrors) => 
        {
            //to check certificate
        };
    
    0 讨论(0)
  • 2021-01-13 02:21

    One possible reason might be the fact that some website provide different result to different browser.

    You can try to provide the browser information to pretend that the call is from a browser.

    var client = new WebClient();
    client.Headers["User-Agent"] = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.15) Gecko/20110303 Firefox/3.6.15";
    string download = client.DownloadString("https://security.ultimatxxxx.com:443/Serverstatus.ashx");
    

    Or

    you have not bind the completedEvent of the Aysnc call.

    0 讨论(0)
提交回复
热议问题