WebRequest myWebRequest=WebRequest.Create("一个无效链接的地址");
myWebRequest.Timeout=5000;
try
{
WebResponse myWebResponse=myWebRequest.GetResponse();
Stream resStream = myWebResponse.GetResponseStream();
StreamReader sr = new StreamReader(resStream, System.Text.Encoding.Default);
this.Label1.Text = sr.ReadToEnd();
resStream.Close();
sr.Close();
}
catch(System.Net.WebException xx)
{
this.Label1.Text=xx.Message;
}
如果label标签显示:无效的地址404错误说明链接无效