1

我在从 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 有一些不允许下载图像的服务器设置?

4

1 回答 1

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

参考:使用 webclient.DownloadFileAsync 下载的文件有 0KB

于 2013-06-13T09:58:27.193 回答