模拟登录JSP网页,目前能登录,也能采集到数据,但过15分钟左右就会网页超时!
httpwatch查看,登录后点击任意页面,Received回来的cookie中expires时间增加,但我取到的cookie只有JSESSIONID与PATH,不能取到expires。Headers Send:
Cookie        BIGipServerpool7001=218366218.22811.0000; JSESSIONID=0000l4kdLP1blfGLZZjNRGzGV-8:11b5cc0lm
Headers Received:
Set-Cookie    BIGipServerpool7001=218366218.22811.0000; expires=Thu, 27-Aug-2009 03:29:27 GMT; path=/response.Cookies与response.Headers["Set-Cookie"]都无法取到expires值

解决方案 »

  1.   

    httpwatch ->cookies
    Cookie Name               Direction         Value            Path            Expires    
    BIGipServerpool7001         Sent     218366218.22811.0000
    BIGipServerpool7001       Received   218366218.22811.0000      /   Thu, 27-Aug-2009 03:49:10 GMT
    JSESSIONID                  Sent   0000l4kdLP1blfGLZZjNRGzGV-8:11b5cc0lm
      

  2.   

    HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(Url);
    myRequest.CookieContainer = new CookieContainer();HttpWebResponse response = (HttpWebResponse)myRequest.GetResponse();
    string s= response.Cookies[""].Value;
      

  3.   

    response.Cookies["Expires"].Value 这样来取吗?
      

  4.   

    学习我也在研究这些东西,但我这里直接获得
     public void SetCookieContainer(CookieCollection CookieCC)
            {
                CookieCtainer.Add(CookieCC);
            }
            public void SetCookieCollection(CookieCollection CookieCC)
            {
                CookieCtion=CookieCC;
            } public string Login(string url, string strPost, RequestPPT rePpt)//string user, string password, string checkcode
            {
                string outHtml = "";
                try
                {
                    byte[] data = Encoding.Default.GetBytes(strPost);
                    HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
                    myRequest.Method = rePpt.Method;
                    myRequest.ContentType = rePpt.ContentType;
                    myRequest.CookieContainer = CookieCtainer;
                    myRequest.ContentLength = data.Length;
                    Stream newStream = myRequest.GetRequestStream();
                    // Send the data.   
                    newStream.Write(data, 0, data.Length);
                    newStream.Close();                // Get response   
                    HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
                    StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.Default);
                    outHtml = reader.ReadToEnd();
                    SetCookieCollection(myResponse.Cookies);
                    SetCookieContainer(myResponse.Cookies);
                    return outHtml;
                }
                catch (Exception ee)
                {
                    outHtml = ee.Message;
                    return outHtml;
                }
            }
    但不知道会不会解决问题,还有如果失效了,重新登入下继续用,失效会返回一个不是正常网页的错误 一旦有这个错误 我这里就重新调用Login 继续得到新的
      

  5.   

    我用webClient没碰到过这种事,除非这个cookie是调用js生成的
      

  6.   

    cookie能取到,主要该网站有验证码,无法重新登录!
    目前怀疑cookie过期的问题,我去到的cookie里只有JSESSIONID与PATH,没有其他值。
    但带这个cookie去抓取数据,还是成功的,那SESSIONID肯定是对的。
    cookie内是否必定有Expires值?
            public CookieCollection cookieCol;
            public void AddCookieWithCookieHead(ref CookieCollection cookieCol, string cookieHead, string defaultDomain)
            {
                if (cookieCol == null) cookieCol = new CookieCollection();
                if (cookieHead == null) return;
                string[] ary = cookieHead.Split(';');
                for (int i = 0; i < ary.Length; i++)
                {
                    Cookie ck = GetCookieFromString(ary[i].Trim(), defaultDomain);
                    if (ck != null)
                    {
                        cookieCol.Add(ck);
                    }   
                }
            }
            取到的cookie内容如下:
            cookieCol.Count.ToString() = 2
            cookieCol[0].Name = JSESSIONID
            cookieCol[1].Name = PATH