我想从某网站下下载Rss数据,希望在下载前检测网站是否可连接,请问如何检测?

解决方案 »

  1.   

    否可连接
    -----------[DllImport("wininet.dll")]
            private extern static bool InternetCheckConnection(String url, int flag, int ReservedValue);
            public bool GetExtranet()
            {
                bool extranet = false;
                try
                {
                    if (InternetCheckConnection("http://news.163.com/special/00011K6L/rss_newstop.xml", 1, 0).Equals(false))
                    {
                        extranet = false;
                    }
                    else
                    {
                        extranet = true;
                    }
                }
                catch (Exception e)
                {
                    e.ToString();
                }
                return extranet;
            }下载Rss数据 存到XML
    ------
    string URL = "http://news.163.com/special/00011K6L/rss_newstop.xml";
    XmlDocument xmldocument = new XmlDocument();
                    xmldocument.Load(URL);
                    xmldocument.Save(System.Windows.Forms.Application.StartupPath + ("~doc.xml"));试试...
      

  2.   

    try  
      {  
      HttpWebRequest  request=(HttpWebRequest)WebRequest.Create("");  
      HttpWebResponse  myResponse=(HttpWebResponse)request.GetResponse();  
      if(myResponse.StatusDescription.ToString().ToUpper()=="")  
      {    }  
      }  
      catch(WebException  webExcp)  
      {  
      }
      

  3.   

    我是在公司内部通过代理上网的。
    这个方法好像不管用
    一直提示false