Sample code for 30+ languages & platforms
Lazarus Pascal

Inspect HTTP Request Header

Demonstrates the LastHeader property.

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.HttpResponse,
  Chilkat.Http;

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

procedure RunDemo;
var
  success: Boolean;
  http: THttp;
  url: string;
  json: string;
  resp: THttpResponse;

begin
  success := False;

  http := THttp.Create;

  url := 'https://chilkatsoft.com/echo_request_body.asp';
  json := '{"greeting":"Hello World"}';

  //  Send a POST with the JSON in the HTTP request body.
  resp := THttpResponse.Create;
  success := http.HttpStr('POST',url,json,'utf-8','application/json',resp);
  if (success = False) then
    begin
      WriteLn(http.LastErrorText);
      Exit;
    end;

  //  Examine the HTTP request header we just sent.
  WriteLn(http.LastHeader);

  //  Output:

  //  POST /echo_request_body.asp HTTP/1.1
  //  Host: chilkatsoft.com
  //  Accept: */*
  //  Accept-Encoding: gzip
  //  Content-Type: application/json
  //  Content-Length: 26


  http.Free;
  resp.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.