Home:ALL Converter>C# Download file from URL

C# Download file from URL

Ask Time:2015-09-22T21:34:14         Author:C0deGen

Json Formatter

Can anybody tell me how i can download file in my C# program from that URL: http://www.cryptopro.ru/products/cades/plugin/get_2_0

I try to use WebClient.DownloadFile, but i'm getting only html page instead of file.

Author:C0deGen,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/32718348/c-sharp-download-file-from-url
Alex K. :

Looking in Fiddler the request fails if there is not a legitimate U/A string, so:\n\nWebClient wb = new WebClient();\nwb.Headers.Add(\"User-Agent\", \"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.33 Safari/537.36\");\nwb.DownloadFile(\"http://www.cryptopro.ru/products/cades/plugin/get_2_0/cadeplugin.exe\", \"c:\\\\xxx\\\\xxx.exe\");\n",
2015-09-22T14:04:44
Slashy :

I belive this would do the trick.\n\nWebClient wb = new WebClient();\nwb.DownloadFile(\"http://www.cryptopro.ru/products/cades/plugin/get_2_0/cadeplugin.exe\",\"file.exe\");\n",
2015-09-22T13:42:37
Kreshnik :

If you need to know the download status or use credentials in order to make the request, I'll suggest this solution: \n\nWebClient client = new WebClient();\nUri ur = new Uri(\"http://remoteserver.do/images/img.jpg\");\nclient.Credentials = new NetworkCredential(\"username\", \"password\");\nclient.DownloadProgressChanged += WebClientDownloadProgressChanged;\nclient.DownloadDataCompleted += WebClientDownloadCompleted;\nclient.DownloadFileAsync(ur, @\"C:\\path\\newImage.jpg\");\n\n\nAnd her it is the implementation of the callbacks:\n\nvoid WebClientDownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)\n{\n Console.WriteLine(\"Download status: {0}%.\", e.ProgressPercentage);\n}\n\nvoid WebClientDownloadCompleted(object sender, DownloadDataCompletedEventArgs e)\n{\n Console.WriteLine(\"Download finished!\");\n}\n",
2016-07-07T16:19:36
DPac :

Try WebClient.DownloadData\n\nYou would get response in the form of byte[] then you can do whatever you want with that.",
2015-09-22T13:42:47
yy