我正在登录一个网站,试图让cookies运行起来。据我所知,将IdCookieManager分配给IdHTTP并设置AllowCookies:=true应该是我需要做的全部工作,对吧?我在登录后成功地收到了cookie,但当我尝试进一步导航时,该cookie未被发送。
下面是我的代码:
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。
谢谢
发布于 2012-07-16 16:41:59
好吧,这是个很愚蠢的问题。问题是登录部分使用http://navratdoreality.cz,而下一部分使用http://www.navratdoreality.cz。这两个URL显示相同,但对于IdCookieManager,它们明显不同,所以这就是不发送cookie的原因。
https://stackoverflow.com/questions/11496173
复制相似问题