关注联楷|返回首页 | 网站案例 | 帮助中心

合作共赢、快速高效、优质的网站建设提供商

上海网站建设 

服务热线:021-61394118

上海联楷科技

用C#判断一个网址是否正常

作者:佚名   时间:2012-04-29   分享到:

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 = "linksj.com 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;
           }
       }



如没特殊注明,文章均为上海联楷网络原创,转载请注明来自:http://www.linksj.com/contact/20151229/n7614.html

上海联楷网络新闻