首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >IdHTTP未发送cookies的IdCookieManager

IdHTTP未发送cookies的IdCookieManager
EN

Stack Overflow用户
提问于 2012-07-16 06:28:42
回答 1查看 2.3K关注 0票数 1

我正在登录一个网站,试图让cookies运行起来。据我所知,将IdCookieManager分配给IdHTTP并设置AllowCookies:=true应该是我需要做的全部工作,对吧?我在登录后成功地收到了cookie,但当我尝试进一步导航时,该cookie未被发送。

下面是我的代码:

代码语言:javascript
复制
procedure TForm1.Login;
var data: TStringList;
begin
  data:=TStringList.Create;

  try
    IdHTTP.Get('http://navratdoreality.cz/'); // Here I receive Set-Cookie

    data.Add('ACTION=check_adult');
    data.Add('check=18plus');

    Memo1.text:=IdHTTP.Post('http://navratdoreality.cz/',data); // Here the 
     // request contains the cookie and I get a succesfully-logged page in 
     // response, no more set-cookie
  except
    ShowMessage('err');
  end;

  data.Free;
end;

procedure TForm1.Navigate;
var ms:TMemoryStream;
begin
  ms:=TMemoryStream.Create;
  try
    IdHTTP.Get('http://www.navratdoreality.cz/?p=view&id='+Edit1.Text, ms); 
    // the request doesn't contain any cookies, even though the cookie from 
    // logging is saved in IdCookieManager

    ms.Position:=0;
    Memo1.Lines.LoadFromStream(ms, TEncoding.UTF8);
  except
    ShowMessage('err');
  end;

  ms.Free;
end;

我不知道问题出在哪里。我的Indy是10.5.8.0。如果你要查看这个网站,请注意,其中一些是nsfw。

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-07-16 16:41:59

好吧,这是个很愚蠢的问题。问题是登录部分使用http://navratdoreality.cz,而下一部分使用http://www.navratdoreality.cz。这两个URL显示相同,但对于IdCookieManager,它们明显不同,所以这就是不发送cookie的原因。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11496173

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档