使用webclient方法下载文件 [英] download a file using webclient method
问题描述
我已经完成了从URL下载文件的任务,我已经编写了以下函数
void DownloadFile( string downloadLocation, string destinationLocation)
{
WebClient myWebClient = new WebClient();
myWebClient.DownloadFile(downloadLocation,destinationLocation);
}
上面的代码似乎在我试图下载的一些文件上工作正常但无法工作所有在一个特定领域。可能是什么问题?当然是解决方案?
例如:
DownloadFile( http://www.abc.com/1.jpg, @ C:\1.jpg); // 工作正常
DownloadFile( http://www.abc.com/2.jpg, @ C:\2.jpg跨度>); // 工作正常
DownloadFile( http://www.abc123.com/21.jpg, @ C:\21.jpg跨度>); // 工作正常
但
DownloadFile( http://www.xyz.com/a.jpg, @ C:\a.jpg跨度>); // 不起作用
DownloadFile( http://www.xyz.com/abcd.jpg, @ C:\abcd.jpg); // 不起作用
<对于那些认为我在开玩笑的人来说,
...当通过任何浏览器调用时,所有文件都可以轻松下载,包括IE,firefox和chrome
< blockquote>一种可能性,我真的不记得以前是否遇到过它,有时服务器上的某些代理和诸如此类的内容可能会禁止人们下载文件。每个服务器都有不同的配置,也许这个配置阻止某些Web请求。请问,实际域名是什么? (我认为它不是xyz.com)...
I have been given a task to download a file from URL for which i have written the following function
void DownloadFile(string downloadLocation, string destinationLocation)
{
WebClient myWebClient = new WebClient();
myWebClient.DownloadFile(downloadLocation, destinationLocation);
}
The above code seems to be working fine on a number of files I ve tried to download but cannot work at all on one particular domain. What could be the issues?? and ofcourse the solution?
for Eg:
DownloadFile("http://www.abc.com/1.jpg", @"C:\1.jpg"); //works fine
DownloadFile("http://www.abc.com/2.jpg", @"C:\2.jpg"); //works fine
DownloadFile("http://www.abc123.com/21.jpg", @"C:\21.jpg"); //works fine
but
DownloadFile("http://www.xyz.com/a.jpg", @"C:\a.jpg"); //doesn't work
DownloadFile("http://www.xyz.com/abcd.jpg", @"C:\abcd.jpg"); //doesn't work
for those who think i am joking around ... all the files are easily downloadable when called via any browser including IE, firefox and chrome
One possibility, and I can't really remember if I've encountered it before, is sometimes certain proxies and whatnot on the server may prohibit people from downloading their files. Each server has a different configuration, and maybe this one is blocking certain web requests. May I ask, what is the actual domain? (I take it it's not xyz.com)...
这篇关于使用webclient方法下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!