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;
}
}
转载于:https://www.cnblogs.com/sunny-539/p/3571944.html