问题
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