Sample code for 30+ languages & platforms
Lazarus Pascal Requires Chilkat v11.1.0+

Example: Http.ClearInMemoryCookies method

Demonstrates how to call the ClearInMemoryCookies method.

Chilkat Lazarus Pascal Downloads

Lazarus Pascal
program ChilkatDemo;

// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}

uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}
  SysUtils,
  CkDllLoader,
  Chilkat.Http;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  http: THttp;
  html: string;
  xmlStr: string;

begin
  http := THttp.Create;

  //  Save received cookies to an in-memory cache.
  http.CookieDir := 'memory';
  http.SaveCookies := True;

  //  Indicate that saved cookies should be sent on subsequent requests (where the cookie's attributes match the request)
  http.SendCookies := True;

  html := http.QuickGetStr('https://www.paypal.com/');

  //  Examine the cookies cached for the domain paypal.com
  xmlStr := http.GetCookieXml('paypal.com');
  WriteLn(xmlStr);

  //  Sample output:
  //  <?xml version="1.0" encoding="utf-8"?>
  //  <cookies>
  //      <cookie key="/,/,$x-enc" v="0" maxAge="1800">
  //          <x-enc>URI_ENCODING</x-enc>
  //      </cookie>
  //      <cookie key=".paypal.com,/,LANG" v="0" expire="Fri, 15 Aug 2025 23:42:44 GMT" maxAge="31556000" secure="yes">
  //          <LANG>en_US%3BUS</LANG>
  //      </cookie>
  //      <cookie key="paypal.com,/,ts" v="0" expire="Mon, 14 Aug 2028 14:56:50 GMT" secure="yes">
  //          <ts>vreXpYrS%3D1848964208%26vteXpYrS%3D1755271608%26vr%3Dae3bc3371987669703182e1efffffffe%26vt%3Dae3bc337198369703182e1efffffffd%26vtyp%3Dnew</ts>
  //      </cookie>
  //      <cookie key="paypal.com,/,ts_c" v="0" expire="Mon, 14 Aug 2028 14:56:50 GMT" secure="yes">
  //          <ts_c>vr%3Dae3bc3371987365703182e1efffffffe%26vt%3Dae3bc337198759703182e1efffffffd</ts_c>
  //      </cookie>
  //  </cookies>

  //  Clear the in-memory cookies.
  http.ClearInMemoryCookies();

  //  The cached cookies should not be present.
  xmlStr := http.GetCookieXml('paypal.com');
  WriteLn('After calling ClearInMemoryCookies...');
  WriteLn(xmlStr);
  WriteLn('----');


  http.Free;

end;

// ---------------------------------------------------------------------------

begin

  try
    RunDemo;
  except
    on E: Exception do
      WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
  end;

  WriteLn;
  {$IFDEF MSWINDOWS}
  WriteLn('Press Enter to exit...');
  ReadLn;
  {$ENDIF}
end.