【发布时间】:2010-12-27 13:46:40
【问题描述】:
如果之前讨论过这个问题,很抱歉再次询问..
我想使用 System.Net.WebClient 类从 url 下载图像。
当我尝试下载图像(即 google 徽标)时。它没有出现任何错误,但有些图像出现错误。我不明白为什么会出现此错误。
我该如何解决这个问题?
我的代码是:
WebClient client = new WebClient();
try
{
//Downloads the file from the given url to the given destination
client.DownloadFile(urltxt.Text, filetxt.Text);
return true;
}
catch (WebException w)
{
MessageBox.Show(w.ToString());
return false;
}
catch (System.Security.SecurityException)
{
MessageBox.Show("securityexeption");
return false;
}
catch (Exception)
{
MessageBox.Show("exception");
return false;
}
错误是:
System.Net.WebException:底层连接已关闭:接收时出现意外错误。-->System.IO.IOException:无法从传输连接中读取数据:现有连接被远程强制关闭host.-->System.Net.Sockets.SocketException:An现有连接被远程主机强行关闭...bla bla
感谢您的帮助。
【问题讨论】: