我用IdHTTP.post 登录上了一个网站,然后在登录的情况下,访问该网站的其它网页。post返回的值显示登录成功了,但是我访问其它网页时,却发现连接已经断开。请问如何解决。

解决方案 »

  1.   

    POST登陆成功以后取COOKIE
    访问别的页面时把COOKIE带上
      

  2.   

    就是在这里怎么才能把访问别的页面时把COOKIE带上
      

  3.   

    var
      Param:TStringList;
      RStream:TStringStream;
      i:integer;
    begin
     Param:=TStringList.Create;
      RStream:=TStringStream.Create('');
      try
     Param.Add('smsm=ceshi123');
      Param.Add('smsxm=ceshi123');
      memo1.lines.add(IdHTTP1.Post('http://www.xxxxxxxxxxxxx.com/,Param));
     Cookies.Clear;
      Cookies.lines.add(inttostr(CookieMngr.CookieCollection.Count));
      for   i   :=   0   to   CookieMngr.CookieCollection.Count   -   1   do
    Cookies.Lines.Add(CookieMngr.CookieCollection.Items[i].CookieText);
    finally
    Param.Free;
    RStream.Free;end;
    end;
    然后在访问别的页面就是
    var
      Param:TStringList;
      RStream:TStringStream;
    begin
      Param:=TStringList.Create;
      RStream:=TStringStream.Create('');
     Edit2.Text   :=   HTTPEncode(Edit1.Text);
    //IdHttp1.Request.SetHeaders;
    // IdHttp1.Request.RawHeaders.Values['Cookie']:='0';//IdHttp1.Request.CustomHeaders.add(Cookies.text);
     Param.Add('kfgldl=ceshi123');
     Param.Add('txtMobileList=xxxxxxxxx');
     Param.Add('txtSms=222222');
     Param.Add('txtSpli=1');
      Param.Add('zhgls=70');
       memo2.lines.add(IdHTTP1.Post('http://www.xxxxxxx.com/xxxxxx.asp?',Param));
    反回<script>alert('温馨小提示:登录超时,请重新登录!');top.location.href='/';</script>
      

  4.   

    用INDY10吧。
    有自动保存COOKIE的功能。
    D7里的INDY9没有此功能。
      

  5.   

    以get为例,伪造session                IdHttp1.Get(mURL1); 
                    mStr   :=   IdHttp1.Response.CustomHeaders.Values[ 'Set-Cookie']; 
                    if   Pos( ';',mStr)> 0   then 
                                    Session_ID   :=   LeftBStr(mStr,Pos( ';',mStr)-1) 
                    else 
                                    Session_ID   :=   mStr;                 IdHttp1.Request.CustomHeaders.Add( 'Cookie:'   +   Session_ID); 
                    IdHttp1.Get(mURL2); 
    D7的INDY9