C# HTTPS路径的pdf文件下载

 public void ces2()
        {
            try
            {


                var url = "https://116.204.71.115/httpsCs.pdf";//路径地址
         string fileName = "D:\\替换文件\\files.pdf";//下载路径地址
                //ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
                ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
                ServicePointManager.ServerCertificateValidationCallback += ValidateCertificate;

                using (var client = new WebClient())
                {
                    client.DownloadFile(url, fileName);
                }
                Console.WriteLine($"PDF file downloaded and saved as {fileName}");
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }

        }

  

posted @ 2023-07-06 17:39  fulllove  阅读(311)  评论(0编辑  收藏  举报