Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Download file from URL

Tags:

c#

file

download

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.

like image 442
C0deGen Avatar asked Sep 22 '15 13:09

C0deGen


1 Answers

Looking in Fiddler the request fails if there is not a legitimate U/A string, so:

WebClient wb = new WebClient();
wb.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");
wb.DownloadFile("http://www.cryptopro.ru/products/cades/plugin/get_2_0/cadeplugin.exe", "c:\\xxx\\xxx.exe");
like image 72
Alex K. Avatar answered Oct 02 '22 17:10

Alex K.