C# 如何从http服务器下载在允许下载之前需要引用的文件?

C# 如何从http服务器下载在允许下载之前需要引用的文件?,c#,.net,vb.net,C#,.net,Vb.net,我通常使用以下代码下载文件: My.Computer.Network.DownloadFile("url of the file","filepath to save the file") 但最近我遇到了一个站点,它只允许从其站点单击文件下载,而不允许从vb.net代码直接下载 我的问题是:如何从http服务器下载需要引用才能允许下载的文件?尝试手动添加引用器头: WebClient wc = new WebClient(); wc.Headers.Add("Referer","http://

我通常使用以下代码下载文件:

My.Computer.Network.DownloadFile("url of the file","filepath to save the file")
但最近我遇到了一个站点,它只允许从其站点单击文件下载,而不允许从vb.net代码直接下载


我的问题是:如何从http服务器下载需要引用才能允许下载的文件?

尝试手动添加引用器头:

WebClient wc = new WebClient();
wc.Headers.Add("Referer","http://whatever.com");
wc.DownloadFile("url of the file","filepath to save the file");

为什么要将其标记为vb.net和c#?您的代码似乎是VB。NET@Icarus:我可以使用代码转换器转换为VB.NET