Sample code for 30+ languages & platforms
Pascal (Lazarus/Delphi)

Send HTTPS POST with XML Body

See more HTTP Examples

Demonstrates how to send an HTTP (or HTTPS) POST where the body of the request is XML.

Chilkat Pascal (Lazarus/Delphi) Downloads

Pascal (Lazarus/Delphi)
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;
  strXml: string;
  resp: THttpResponse;

begin
  success := False;

  //  This example requires the Chilkat API to have been previously unlocked.
  //  See Global Unlock Sample for sample code.

  http := THttp.Create;

  strXml := '<TransactionSetup xmlns="https://xyz.com"><Credentials><AccountID>XXX</AccountID></Credentials></TransactionSetup>';

  //  Maybe you need other headers?
  http.SetRequestHeader('Accept','application/xml');

  resp := THttpResponse.Create;
  success := http.HttpStr('POST','https://www.somewebsite.com/',strXml,'utf-8','application/xml',resp);
  if (success = False) then
    begin
      WriteLn(http.LastErrorText);
      Exit;
    end;

  //  Examine the response status code:
  WriteLn('response status code = ' + resp.StatusCode);

  //  Examine the response body:
  WriteLn('response body: ' + resp.BodyStr);


  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.