C# 在C中使用Webclient时,如何忽略SSL检查#

C# 在C中使用Webclient时,如何忽略SSL检查#,c#,wpf,ssl,C#,Wpf,Ssl,我正在尝试以字符串形式获取此URL的内容 这是我正在使用的代码: var html_content = ""; using (var client = new WebClient()) { client.Headers.Add("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like

我正在尝试以字符串形式获取此URL的内容

这是我正在使用的代码:

        var html_content = "";

        using (var client = new WebClient())

        {


            client.Headers.Add("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.1 Safari/537.36");

            html_content += client.DownloadString("https://noembed.com/embed?url=https://www.youtube.com/watch?v=1FLhOGOg2Qg");


        }
        Console.WriteLine(html_content);
        Console.ReadLine();
这就是我得到的错误:

System.Net.WebException was unhandled
  HResult=-2146233079
  Message=The request was aborted: Could not create SSL/TLS secure channel.
  Source=System

我在一个WPF应用程序上使用它,我可以在这里忽略SSL。我已经尝试过忽略SSL的其他答案,但没有一个有效。它可以与其他URL一起使用,例如,但不能与noembed.com URL一起使用。

添加ServicePointManager.SecurityProtocol=SecurityProtocolType.Tls12; 这对我很有用:

var html_content = "";
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

        using (var client = new WebClient())

        {


            client.Headers.Add("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.1 Safari/537.36");

            html_content += client.DownloadString("https://noembed.com/embed?url=https://www.youtube.com/watch?v=1FLhOGOg2Qg");


        }
        Console.WriteLine(html_content);
        Console.ReadLine();
我得到的输出:

{“author_url”:“url”:“provider_url”:“title”:“ONE FOR THE MONEY拖车2011官方[HD]Katherine Heigl”,“author_name”:“流媒体剪辑”,“键入”:“视频”,“高度”:270,“缩略图高度”:360,“缩略图宽度”:480,“提供商名称”:“YouTube”,“html”:\nhttps://www.youtube.com/embed/1FLhOGOg2Qg?feature=oembed\“frameborder=\“0\”allowfullscreen=\“allowfullscreen\”>\n,“缩略图url:”,“版本”:“1.0”,“宽度”:480}