728x90
// SSL/TLS 오류 해결을 위한 코드
System.Net.ServicePointManager.Expect100Continue = true;
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Ssl3 | System.Net.SecurityProtocolType.Tls | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls12;
System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
System.Net.WebClient webClient = new System.Net.WebClient();
// 파일 다운로드받을 URL
String fileLink = "https://pub.insure.or.kr/compareDis/variableInsrn/prodFund/excelDownloadProfitView.do?prodCd=L011110012700&search_stdYmd=2021-03-29&memberCd=L01";
// 다운로드 받을 폴더/파일 지정해서 다운로드
// **파일명 지정 안하면 오류 발생함
// **확장자가 URL에 업로드된 파일과 다르면 파일이 깨져서 다운로드됨
webClient.DownloadFile(new Uri(fileLink), @"C:\test.xls");
728x90
'프로그래밍 > C#' 카테고리의 다른 글
[C#] VBScipt 실행시키고 결과값 리턴받기 (0) | 2021.06.27 |
---|---|
[C#] datatable타입 변수를 엑셀에 기록(Office 라이센스 필요없음) (0) | 2021.06.24 |
[C#] zip 파일로 폴더/파일 압축 및 압축 해제 (0) | 2021.03.29 |
[C#] C#에서 VBScript 실행시키기 (0) | 2021.03.29 |
[C#] C#에서 python 스크립트를 불러오고 argument 주고받기 (0) | 2021.03.26 |