码迷,mamicode.com
首页 > Windows程序 > 详细

C#判断网站是否可以正常访问

时间:2014-11-20 20:16:08      阅读:244      评论:0      收藏:0      [点我收藏+]

标签:des   http   io   os   sp   on   bs   ef   as   


            String PageUrl = "url";
           try
           {  
               HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(PageUrl);
               myHttpWebRequest.Credentials = CredentialCache.DefaultCredentials;
               HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
               if (myHttpWebResponse.StatusCode == HttpStatusCode.OK)
               {
                   LabelMessage.Text="Response Status Code is OK and StatusDescription is: "+myHttpWebResponse.StatusDescription;
               }
               myHttpWebResponse.Close();
      
           }
           catch(WebException ee)
           {
               LabelMessage.Text = "WebException Raised. The following error occured : " + ee.Status;
           }
           catch(Exception ee)
           {
               LabelMessage.Text = "The following Exception was raised : " + ee.Message;
           }
      

C#判断网站是否可以正常访问

标签:des   http   io   os   sp   on   bs   ef   as   

原文地址:http://www.cnblogs.com/yixingmeng/p/4111372.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!