我用IdHTTP的POST功能可以登录上网页,但是再想取登录后点击的其它链接里的内容就会报错,我想大概可能是网页检测到没登录又回到登录页去了

解决方案 »

  1.   

    idhttp.get('http://www.test.com?username=test&pwd=adfaf')
    取回整个页面内容
      

  2.   

    登录后要取回Cookie,再次取内容时要将Cookie设到IdHTTP.Request.ExtraHeaders中
      

  3.   

    程序大至下:
    var
       Cookie,CookieList:string;
       i:integer;
    ....
    //先登录
    Cookie:='';
    CookieList:='';
    for i:=0 to idhttp1.Response.ExtraHeaders.Count-1 do
        if (UpperCase(copy(IdHTTP1.Response.ExtraHeaders.Strings[i],1,10)) ='SET-COOKIE') then
        begin
               Cookie :=Trim(copy(IdHTTP1.Response.ExtraHeaders.Strings[i],12,1000));
               Cookie :=copy(Cookie,1,Pos(Cookie,';'));
               CookieList:=CookieList+Cookie;
        end;
     IdHTTP1.Request.ExtraHeaders.Add("Cookie: "+CookieList);
    //再用IdHTTP1.Get新的网页
      

  4.   

    但是服务器上的应该是用的session保存的,不是cookies
      

  5.   

    没有ExtraHeaders这个属性,我用的是D7