C#从URL下载文件 [英] C# Download file from URL

查看:216
本文介绍了C#从URL下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我如何从该URL在C#程序中下载文件:
http://www.cryptopro.ru/products/cades/plugin/get_2_0

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

我尝试使用WebClient.DownloadFile,但是我m仅获得html页面而不是文件。

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

推荐答案

在Fiddler中查找,如果没有合法的U / A字符串,则请求失败,所以:

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");

这篇关于C#从URL下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆