2017-12-06 7 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을 무시하고 확인하십시오. 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/", "제목" "비디오 클립", "비디오 클립", "높이": 270, "thumbnail_height": 360, "thumbnail_width": 480, "예고편 2011 공식 [HD] Katherine Heigl", "author_name" "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

고마워요 !! 그것은 일했다 !!! –