各位大哥:
    我今天发现有一个问题,困扰了我好久,也不知道怎样解决,请高手看一看:
try
{
  int i;
  string retdata;
  for (i=1;i<40;i++)
  {
     url="http://www.abc.com/"+i.ToString()+".asp";
     HttpWebRequest req = (HttpWebRequest) WebRequest.Create(url);
     req.CookieContainer=new CookieContainer();
     req.AllowAutoRedirect = true;
     req.MaximumAutomaticRedirections = 3;
     req.UserAgent = "Mozilla/6.0 (MSIE 6.0; Windows NT 5.1; Natas.Robot)";
     req.KeepAlive = true;
     req.Timeout = 40000;
     HttpWebResponse webresponse = (HttpWebResponse) req.GetResponse();     if (webresponse != null) 
     {
StreamReader stream = new StreamReader(webresponse.GetResponseStream(),Encoding.GetEncoding("GB2312"));
retdata=stream.ReadToEnd();
     }
     webresponse.Close();
  }
   catch(System.Exception e) 
   {
       Console.Write("error");
   }
}***************************************************************
我的问题是,程序中间遇到一个页面,返回信息是:(800)内部服务器错误,
在执行HttpWebResponse webresponse = (HttpWebResponse) req.GetResponse();时出错,
原因是该页面被删除或找不到之类的,该错误被catch到,我想跳过这个页面,再进入下一次
循环该怎么做,请各位高手指点一二!!!只要帮了忙的,本人一定给分,大家可以看我以前的记录。

解决方案 »

  1.   

    int i;
      string retdata;
      for (i=1;i<40;i++)
      {
         url="http://www.abc.com/"+i.ToString()+".asp";
         HttpWebRequest req = (HttpWebRequest) WebRequest.Create(url);
         req.CookieContainer=new CookieContainer();
         req.AllowAutoRedirect = true;
         req.MaximumAutomaticRedirections = 3;
         req.UserAgent = "Mozilla/6.0 (MSIE 6.0; Windows NT 5.1; Natas.Robot)";
         req.KeepAlive = true;
         req.Timeout = 40000;
    try
    {
         HttpWebResponse webresponse = (HttpWebResponse) req.GetResponse();     if (webresponse != null) 
         {
    StreamReader stream = new StreamReader(webresponse.GetResponseStream(),Encoding.GetEncoding("GB2312"));
    retdata=stream.ReadToEnd();
         }
         webresponse.Close();
    }
    catch
    {
    continue;
    }