转自:http://www.cnblogs.com/junny/archive/2012/10/30/2745978.html

复制代码
using System.Net;


    public bool CheckUrlVisit(string url) 
    {       
        try
        {
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
            HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
            if (resp.StatusCode == HttpStatusCode.OK)
            {
          resp.Close(); 
return true; } } catch (WebException webex) { return false; } return false; } string[] links = { "http://www.baidu.com", "http://www.google.com", "http://www.chinabuffetflora.com" }; foreach (string link in links) { HttpContext.Current.Response.Write( link+" : "+CheckUrlVisit(link)+" <br>"); }
复制代码

测试结果:

http://www.baidu.com : True 
http://www.google.com : True 
http://www.chinabuffetflora.com : False 

 posted on 2012-11-19 11:40  纳米程序员  阅读(214)  评论(0编辑  收藏  举报