I have Indy 10.6.2.5366 and delphi Tokyo 10.2 update 3.
In a response to an HTTPS POST
, the CookieManager states there are no cookies, but when i do the same request in postman, there's a Cookie called "ROUTEID" in the response.
but when i do the exactly same request on delphi, there is no "ROUTEID" cookie.
i need to persist the cookies because they have authentication information that i need to send in the subsequent requests, as Remy Lebeau states in this post.
I Must be doing something wrong, because in this other post, remy says that TCookieManager were completely re-written from scratch, but what i'm missing?
I've notice that postman shows 10 headers in the response, but delphi shows only 8 in the TIdHTTP.Response.RawHeaders
I know that the response code of my request is 401, but even with an unauthorized error, there's a cookie in the response.
finally, here's my code:
procedure TestMethod(AUrl, ABody: string);
var
HTTP: TIdHTTP;
SSL: TIdSSLIOHandlerSocketOpenSSL;
LStreamRequestBody: TStringStream;
LReturnBody: string;
LCookieList: TIdCookieList;
n: Integer;
begin
HTTP := TIdHTTP.Create(nil);
SSL := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
LStreamRequestBody := TStringStream.Create(ABody, TEncoding.UTF8);
try
IdOpenSSLSetLibPath(Utils.Global.SSLLibPath);
SSL.SSLOptions.Method := sslvSSLv23;
SSL.SSLOptions.SSLVersions := [sslvTLSv1_2, sslvTLSv1_1, sslvTLSv1];
SSL.SSLOptions.Method := sslvSSLv23;
HTTP.IOHandler := SSL;
HTTP.Response.ContentType := 'application/json;charset=utf-8';
HTTP.Request.CustomHeaders.FoldLines := True;
HTTP.Request.Accept := '*/*';
HTTP.Request.ContentType := 'application/json';
HTTP.Request.Connection := 'keep-alive';
HTTP.Request.AcceptEncoding := 'gzip, deflate, br';
HTTP.Request.UserAgent := 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0';
HTTP.CookieManager := TIdCookieManager.Create(nil);
HTTP.AllowCookies := True;
HTTP.HandleRedirects := True;
try
LReturnBody := HTTP.Post(AUrl, LStreamRequestBody);
Except
on e: EIdHTTPProtocolException do
begin
LCookieList := HTTP.CookieManager.CookieCollection.LockCookieList(caRead);
try
for n := 0 to LCookieList.Count - 1 do
begin
end;
finally
HTTP.CookieManager.CookieCollection.UnlockCookieList(caRead);
end;
end;
end;
finally
LStreamRequestBody.Free;
HTTP.Free;
SSL.Free;
end;
end;