Delphi下idHTTP配合CookieManager获取Cookie

2018-10-30

procedure TForm1.Button1Click(Sender: TObject);
var
  Cookies: TidCookies;
  i: integer;
begin
  Memo1.Clear;
  idHTTP1.ProtocolVersion := pv1_1;
  Memo1.Clear;
  IdHTTP1.ProtocolVersion := pv1_1;
  IdHTTP1.Request.UserAgent := 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727)';
  idHTTP1.Get('http://www.baidu.com/s?wd=xtty');
  ShowMessage(idHTTP1.URL.Params);
  ShowMessage(idHTTP1.URL.Document);

  Cookies := IdCookieManager1.CookieCollection;
  for i := 0 to cookies.Count - 1 do
    Memo1.Lines.Add(Cookies.Items[i].CookieName + 'Value:' + Cookies.Items[i].Value);
end;


阅读109