从WebClient.DownloadFile请求返回404错误

时间:2013-06-13 09:43:44

标签: c# webclient downloadfile

我在从tkmaxx.com下载产品图片时遇到困难

http://www.tkmaxx.com/content/ebiz/tkmaxx/invt/B./1./A./21866003/21866003_medium.jpg

try
{
    string filePath = "D:\\temp\\test.jpg";
    WebClient webClient = new WebClient();
    webClient.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
    webClient.DownloadFile("http://www.tkmaxx.com/content/ebiz/tkmaxx/invt/B./1./A./21866003/21866003_medium.jpg", filePath);
}
catch (Exception ex)
{

}

我一直收到404错误消息。我已经看了很多论坛帖子,但我似乎无法解决这个问题。

我唯一可以想到的是TXMAXX.com有一些不允许图像下载的服务器设置?

1 个答案:

答案 0 :(得分:0)

试试这个..

private void button1_Click(object sender, EventArgs e)
  {
   string url = "http://framework.zend.com/releases/ZendFramework-1.11.11/ZendFramework-1.11.11.zip";
   WebClient downloader = new WebClient();
   downloader.DownloadFileCompleted += new AsyncCompletedEventHandler(downloader_DownloadFileCompleted);
   downloader.DownloadProgressChanged += new DownloadProgressChangedEventHandler(downloader_DownloadProgressChanged);
   downloader.DownloadFileAsync(new Uri(url), "C:\\temp.zip");
  }

 void downloader_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
   {
      label1.Text = e.BytesReceived + " " + e.ProgressPercentage;
    }
  void downloader_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
   {
       if (e.Error != null)
         MessageBox.Show(e.Error.Message);
       else
         MessageBox.Show("Completed!!!");
   }

参考:Downloaded file using webclient.DownloadFileAsync has 0KB