在CookiesManager中加载已保存的cookie

时间:2018-04-08 18:09:20

标签: delphi cookies delphi-10.1-berlin

我在将已保存的Cookie加载到CookiesManager时出现问题,错误消息:无效的Cookie日期格式化。 保存饼干: ds_user_id=7459742257; Path=/; Domain=Testing.com; Max-Age=7775999; Expires=Sat, 07-Jul-2018 17:52:03 GMT 我不知道如何解决这个问题

更新

由于rur=FTW; Path=/; Domain=Testing.com; Max-Age=251879107499; Expires=Sat, 01-Jan-10000 06:59:59 GMT中的10000,错误显示 所以我把它改成了2019年,现在它成功加载了,

     var
      S: string;
      Cookies: TIdCookieList;
      Cookie: TIdCookie;
      Uri: TIdURI;
      CookiesList : TStrings;  i : integer;
    begin
      CookiesList := TStringList.create;
      CookiesList.LoadFromFile('path\CookiesList.txt');


      Cookies := IdCookieManager1.CookieCollection.LockCookieList(caReadWrite);
      try
        for I := 0 to CookiesList.count -1 do
        begin
          // read S as needed
          S := CookiesList.Strings[i];
          Uri := TIdURI.Create('testing.com');
          try
            Cookie := IdCookieManager1.CookieCollection.Add;
            try
              Cookie.ParseServerCookie(S, Uri);
              Cookies.Add(Cookie);
            except
              Cookie.Free;
              raise;
            end;
          finally
          Uri.Free;
         end;
        end;
      finally
        IdCookieManager1.CookieCollection.UnlockCookieList(caReadWrite);
        Memo2.TExt := CookiesList.text;
        Cookieslist.free;
      end;
    end;

0 个答案:

没有答案