日期:2014-05-17  浏览次数:20409 次

为什么自己创建的WebClient无法下载百度文库的文章
[i][/i]WebClient wc = new WebClient();
wc.Credentials = new NetworkCredential("xxxxxx", "xxxxxx");
wc.DownloadFile("http://wenku.baidu.com/submit/Linux系统命令及其使用详解.doc", @"c:\4.doc");

上面的网址在浏览器中打开,直接弹出迅雷下载。。。,为什么用webclient下载的doc内容是:
很抱歉,页面没有找到。但是不要着急哦! 
你可以: 
1. 检查刚才的网址输入;
2. 直接搜索要访问的内容 


而用cassinidev在本地部署网站,能够下载网站里的文件,,直接在浏览器中打开也能下载,,

这是什么原理呢。。。

------解决方案--------------------
C# code

string remoteUri = "http://www.contoso.com/library/homepage/images/";
            string fileName = "ms-banner.gif", myStringWebResource = null;
            // Create a new WebClient instance.
            WebClient myWebClient = new WebClient();
            // Concatenate the domain with the Web resource filename.
            myStringWebResource = remoteUri + fileName;
            Console.WriteLine("Downloading File \"{0}\" from \"{1}\" .......\n\n", fileName, myStringWebResource);
            // Download the Web resource and save it into the current filesystem folder.
            myWebClient.DownloadFile(myStringWebResource,fileName);        
            Console.WriteLine("Successfully Downloaded File \"{0}\" from \"{1}\"", fileName, myStringWebResource);
            Console.WriteLine("\nDownloaded file saved in the following file system folder:\n\t" + Application.StartupPath);