2017-12-06 5 views
-1

このURLの内容を文字列として取得しようとしています。C#でWebclientを使用してSSLチェックを無視する方法

https://noembed.com/embed?url=https://www.youtube.com/watch?v=1FLhOGOg2Qg

これは私が使用していますコードです:

 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を無視してOK。私はすでにSSLを無視して他の答えを試みてきましたが、うまくいきませんでした。それは他のURL、例えばhttps://www.youtube.com/watch?v=1FLhOGOg2Qgでは動作しますが、noembed.com URLでは動作しません。

答えて

0

追加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": "https://www.youtube.com/user/nogoodflix"、 "URL": "https://www.youtube.com/watch?v=1FLhOGOg2Qg"、 "PROVIDER_URL": "https://www.youtube.com/"、 "タイトル": "video_name": "video"、 "height":270、 "thumbnail_height":360、 "thumbnail_width":480、 "ビデオクリップ"、 " "provider_name": "YouTube"、 "html": "\ nhttps://www.youtube.com/embed/1FLhOGOg2Qg?feature = oembed" frameborder = \ "0 \" allowfullscreen = \ "allowfullscreen \"> \ n "、" thumbnail_url ":" https://i.ytimg.com/vi/1FLhOGOg2Qg/hqdefault.jpg "、"バージョン ":" 1.0 "、"幅 ":480}

+0

ありがとう!出来た!!! –

関連する問題