Sample code for 30+ languages & platforms
Lazarus Pascal

HTTP Response Inspection

See more HTTP Examples

Demonstrates how to inspect the HTTP response, including the status code, status text, and response headers, for Chilkat methods that don't use an HttpResponse object.

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

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

procedure RunDemo;
var
  http: THttp;
  jsonText: string;
  mime: TMime;
  numHeaders: Integer;
  i: Integer;

begin
  http := THttp.Create;

  //  Returns the contents of the response body.
  jsonText := http.QuickGetStr('https://chilkatsoft.com/helloWorld.json');

  //  Examine the response status code.
  WriteLn('response status code: ' + http.LastStatus);

  //  Examine the response status text
  WriteLn('response status text: ' + http.LastStatusText);

  //  Examine the full response header.
  WriteLn('response header:');
  WriteLn(http.LastResponseHeader);
  WriteLn('----');

  //  Examine the response content-type
  WriteLn('LastContentType = ' + http.LastContentType);

  //  Examine the response last-mod date
  WriteLn('LastModDate = ' + http.LastModDate);

  //  Load the response header into a Chilkat MIME object to access its fields individually.
  mime := TMime.Create;
  mime.LoadMime(http.LastResponseHeader);

  numHeaders := mime.NumHeaderFields;
  i := 0;
  WriteLn('---- MIME Headers ----');
  while i < numHeaders do
    begin
      WriteLn('name:  ' + mime.GetHeaderFieldName(i));
      WriteLn('value: ' + mime.GetHeaderFieldValue(i));
      i := i + 1;
    end;

  WriteLn('----');

  //  Get a header field value by name:
  WriteLn('ETag: ' + mime.GetHeaderField('ETag'));

  //  Output:

  //  response status code: 200
  //  response status text: OK
  //  response header:
  //  Content-Type: application/json
  //  Last-Modified: Sun, 20 Aug 2023 11:36:27 GMT
  //  Accept-Ranges: bytes
  //  ETag: "34c27f8e5ad3d91:0"
  //  Server: Microsoft-IIS/10.0
  //  X-Powered-By: ASP.NET
  //  Date: Sat, 30 Aug 2025 14:38:13 GMT
  //  Content-Length: 22
  //  ----
  //  LastContentType = application/json
  //  LastModDate = 2023-08-20
  //  ---- MIME Headers ----
  //  name:  Content-Type
  //  value: application/json
  //  name:  Last-Modified
  //  value: Sun, 20 Aug 2023 11:36:27 GMT
  //  name:  Accept-Ranges
  //  value: bytes
  //  name:  ETag
  //  value: "34c27f8e5ad3d91:0"
  //  name:  Server
  //  value: Microsoft-IIS/10.0
  //  name:  X-Powered-By
  //  value: ASP.NET
  //  name:  Date
  //  value: Sat, 30 Aug 2025 14:38:13 GMT
  //  name:  Content-Length
  //  value: 22
  //  ----
  //  ETag: "34c27f8e5ad3d91:0"


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