Error with download a file from https using webclient

怎甘沉沦 提交于 2019-12-08 03:53:11

问题


I have create a piece of code that download a file from a given URL using WebClient.

The problem is i am getting the following error when the code is trying to download a file from a HTTPS site.

The remote certificate is invalid according to the validation procedure

This issue happened only on the server not on the local machine, so i also don't know how to debug it.

I have read several answers on the web but didn't find anything that could help me.

The piece of code:

 using (WebClient Client = new WebClient())
        {
            string fileName = System.Configuration.ConfigurationManager.AppSettings["siteUploadedDirectory"] 
            + "/temp/" + Context.Timestamp.Ticks.ToString() 
            + "_" + FileURL.Substring(FileURL.LastIndexOf('/')+1);
            fileName = Server.MapPath(fileName);
            Client.DownloadFile(FileURL, fileName);
            return fileName + "|" + FileURL.Substring(FileURL.LastIndexOf('/')+1);
        }

The URL i am trying:

http://Otakim.co.il/printreferrer.aspx?ReferrerBaseURL=cloudents.com
&ReferrerUserName=ram
&ReferrerUserToken=1
&FileURL=https://www.cloudents.com/d/lzodJqaBYHu/pD0nrbAtHSq

The file URL: FileURL=https://www.cloudents.com/d/lzodJqaBYHu/pD0nrbAtHSq

Any help will be appreciated


回答1:


You can bypass the certificate validation process by following code snieppet

    ServicePointManager.ServerCertificateValidationCallback
 += (sender, certificate, chain, sslPolicyErrors) => true;


来源:https://stackoverflow.com/questions/20955833/error-with-download-a-file-from-https-using-webclient

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!