■ WebClient 클래스를 사용해 HTTPS 파일을 다운로드하는 방법을 보여준다.
▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
using System; using System.Net; using System.Net.Security; using System.Security.Cryptography.X509Certificates; #region 서버 인증서 무결성 콜백 처리하기 - serverCertificateValidationCallback(sender, certificate, chain, sslPolicyErrors) /// <summary> /// 서버 인증서 무결성 콜백 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="certificate">X509 인증서</param> /// <param name="chain">X509 체인</param> /// <param name="sslPolicyErrors">SSL 정책 에러</param> /// <returns>처리 결과</returns> private bool serverCertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { if(sslPolicyErrors == SslPolicyErrors.None) { return true; } Console.WriteLine ( "X509Certificate [{0}] Policy Error : {1}", certificate.Subject, sslPolicyErrors.ToString() ); return false; } #endregion ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; ServicePointManager.ServerCertificateValidationCallback += serverCertificateValidationCallback; using(WebClient client = new WebClient()) { client.DownloadFile("https://raw.githubusercontent.com/pjreddie/darknet/master/cfg/yolov3-tiny.cfg", "d:\\yolov3-tiny.cfg"); } |