asp.net如何判断网址能否打开
private void StatusDescription_Click(object sender, System.EventArgs e)
{
PageUrl = UrlText.Text;
try
{
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(PageUrl);
myHttpWebRequest.Credentials = CredentialCache.DefaultCredentials;
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
if (myHttpWebResponse.StatusCode == HttpStatusCode.OK)
{
ContentHtml.Text = "Response Status Code is OK and
StatusDescription is: "+myHttpWebResponse.StatusDescription;
}
myHttpWebResponse.Close();
}
catch(WebException ee)
{
ContentHtml.Text = "WebException Raised. The following error occured : "+ee.Status;
}
catch(Exception ee)
{
ContentHtml.Text = "The following Exception was raised : "+ee.Message;
}
}