Cookies are now handled trough the CookieManager class.
You must create a new CookieManager instance (at design time or at runtime), and affect it to the CookieManager property of your IdHTTP object.
Then cookies can then be added with:
procedure AddServerCookie(const ACookie: String; AURL: TIdURI);
procedure AddServerCookies(const ACookies: TStrings; AURL: TIdURI);
For instance (design time sample):
- add an IdHTTP (called MyIdHTTP) to a new form Form1,
- add an IdCookieManager (called MyIdCookieManager - TIdCookieManager is in "Indy Misc Protocols" tab),
- affect MyIdCookieManager to the CookieManager property of MyIdHTTP,
- add a pushbutton,
- use the following test code
uses ..., IdURI, ...;
function AddCookie(const sData, sURL: string; const MyIdCookieManager: TIdCookieManager): boolean;
var MyIdURI: TIdURI;
begin
result := true;
MyIdURI := TIdURI.Create(sURL);
try
MyIdCookieManager.AddServerCookie(sData, MyIdURI);
except
result := false;
end;
MyIdURI.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
var MyCookies: string;
var i: integer;
begin
if not AddCookie('MyCookieValue=MyValue', 'http://www.mywebsite.com/', MyIdHTTP.CookieManager) then
ShowMessage('Error when adding my cookie')
else
begin
MyCookies := '';
for i:=0 to Pred(MyIdHTTP.CookieManager.CookieCollection.Count) do
MyCookies := MyCookies + MyIdHTTP.CookieManager.CookieCollection.Cookies[i].ClientCookie+'~';
ShowMessage('MyCookies = ' + MyCookies);
end;
end;