Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# can';无法使用https获取web响应_C#_Ssl_Https_Certificate - Fatal编程技术网

C# can';无法使用https获取web响应

C# can';无法使用https获取web响应,c#,ssl,https,certificate,C#,Ssl,Https,Certificate,我使用此代码获取web内容,但在WebResponse myResponse=myRequest.GetResponse()处获取异常 我知道它需要SSL/TLS证书,但我想知道为什么我仍然会出错 试试这个 static void Main(string[] args) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | Se

我使用此代码获取web内容,但在
WebResponse myResponse=myRequest.GetResponse()处获取异常

我知道它需要SSL/TLS证书,但我想知道为什么我仍然会出错

试试这个

    static void Main(string[] args)
    {
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
        var client = new HttpClient();
        var result = client.GetAsync("https://www.ecfr.gov").Result;
        var str = result.Content.ReadAsStringAsync().Result;
    }

任何时候你“得到异常”你都需要告诉我们异常是什么。
    static void Main(string[] args)
    {
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
        var client = new HttpClient();
        var result = client.GetAsync("https://www.ecfr.gov").Result;
        var str = result.Content.ReadAsStringAsync().Result;
    }