asp.net如何判断网址能否打开
2014-02-27 17:12
337 查看
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;
}
}
{
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;
}
}
相关文章推荐
- asp.net 文件夹如何在VS2008打开
- 如何用C#在Asp.net中实现打开新网页而不关闭当前页
- Asp.Net 中如何判断用户是否在线
- asp.net中上传如何判断要上传的文件已经存在
- (原创)在 ASP.NET 中,如何巧用 HttpModule ,以实现系统全局登录逻辑判断,高手慎入
- asp.net如何判断地址栏是传值
- ASP.NET MVC中如何在客户端进行必要的判断
- ASP.NET Core开发-如何配置Kestrel 网址Urls
- ASP.NET中如何删除最近打开的项目和文件的记录
- ASP.NET(c#)如何判断浏览器是否支持cookies
- 如何打开别人的ASP.net项目
- asp.net C# FileUpload 控件如何判断文件名的后缀
- 如何用C#在Asp.net中实现打开新网页而不关闭当前页
- asp.net中winform窗体程序如何打开浏览器,如何打开链接?
- asp.net 如何使用js来判断一个网页是否处于iframe中
- 如何用C#在Asp.net中实现打开新网页而不关闭当前页
- 如何打开ASP.NET Configuration页面
- asp.net 中如何判断字符串中有几个逗号 (asp也通用)
- ASP.NET&C#学习笔录2(vs2010项目如何在vs2008中打开 )