I have a cookiesmanager attached to IdHTTP component in a form.
var
XMLRqst : string;
XMLResponse : TStringStream;
XMLRequest : TStringStream;
...
begin
...
IdHTTP1.CookieManager.CookieCollection.Add;
IdHTTP1.CookieManager.CookieCollection[ IdHTTP1.CookieManager.CookieCollection.Count -1 ].CookieName := 'data';
IdHTTP1.CookieManager.CookieCollection[ IdHTTP1.CookieManager.CookieCollection.Count -1 ].Value := '<root user="yyy" company="xxxx">';
IdHTTP1.CookieManager.CookieCollection[ IdHTTP1.CookieManager.CookieCollection.Count -1 ].Path := '/';
...
XMLRequest := TStringStream.Create( XMLRqst, TEncoding.Unicode );
...
idHTTP1.Post( 'http://mysite/api', XMLRequest, XMLResponse );
idHTTP1.Disconnect;
I am never receiving the "data" cookie.
- How to send properly cookies with http post trough Indy's IdHTTP component in Delphi XE6?
TIdCookieManager
handles that for you automatically. That is its sole purpose - to collect cookies sent by the server, and then send those cookies back to the server when appropriate. The only time you should ever be creating cookies manually is if you need to persist them across multiple sessions of your app.TIdCookieManager
does not save cookies persistently when the app is shut down, you would have to save them yourself and then re-load them the next time the app is run. – Remy Lebeau