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

WIN Air Freight Login POST Request

See more HTTP Misc Examples

Demonstrates the "login" POST method endpoint to obtain an initial authToken as a cookie. Each API request will return a fresh authToken cookie which must be passed back to WIN in the next API request.

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

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

procedure RunDemo;
var
  success: Boolean;
  http: THttp;
  xml: TXml;
  httpRequestBody: string;
  resp: THttpResponse;
  xmlResponse: TXml;

begin
  success := False;

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

  http := THttp.Create;

  //  Set the "Accept" header to tell the web server that we'll accept an XML response.
  http.Accept := 'application/xml';
  //  Tell Chilkat to cache any received cookies to files in a particular directory
  http.CookieDir := 'c:/qa_data/cookies';
  http.SaveCookies := True;

  xml := TXml.Create;
  xml.Tag := 'LogOnModel';
  xml.NewChild2('UserName','win-air-freight-user@company.com');
  xml.NewChild2('Password','win-air-freight-password');
  xml.EmitXmlDecl := False;

  httpRequestBody := xml.GetXml();
  resp := THttpResponse.Create;
  success := http.HttpStr('POST','http://integration.winwebconnect.com/api/v1/Login',httpRequestBody,'utf-8','application/xml',resp);
  if (success = False) then
    begin
      WriteLn(http.LastErrorText);
      Exit;
    end;

  xmlResponse := TXml.Create;
  xmlResponse.LoadXml(resp.BodyStr);

  //  See below for an example XML response body.
  WriteLn('Response Body:');
  WriteLn(xmlResponse.GetXml());
  WriteLn('---');

  WriteLn('Response Header:');
  WriteLn(resp.Header);

  //  An example resp header:
  //  
  //  	Cache-Control: no-cache
  //  	Pragma: no-cache
  //  	Content-Length: 1671
  //  	Content-Type: application/xml; charset=utf-8
  //  	Expires: -1
  //  	Set-Cookie: authToken=1467EC8A5D2F1390F89F9DB65AAAAB5C709D1AE7275B72B6DDBDA44C54AE5D5C19648F76AAB12C9D9E2690F0DD69BE6E1C0F6D725C9392E99E1904A6B76D7852948C01A49E2FF20914092843C062778B91EE7497DDF4C1AC4117110E414195C9726E3467BD98094437044A8E94F1BCA1; path=/; HttpOnly
  //  	Access-Control-Allow-Origin: http://integration.winwebconnect.com
  //  	Date: Mon, 21 Nov 2016 21:29:57 GMT
  WriteLn('Success.');

  //  An example XML response body:
  //  -----------------------------
  //  	<?xml version="1.0" encoding="utf-8" ?>
  //  	<AuthResponseDTO>
  //  	    <LastLogin>2016-11-21T21:29:58.229986Z</LastLogin>
  //  	    <UserDetails>
  //  	        <ContactID>16528</ContactID>
  //  	        <AgentID>96592</AgentID>
  //  	        <FirstName>System</FirstName>
  //  	        <LastName>User</LastName>
  //  	        <Email>test@company.com</Email>
  //  	        <JobTitle />
  //  	        <ContactNumber />
  //  	        <IsActivated>true</IsActivated>
  //  	        <OperatedBy />
  //  	        <AddressBookID />
  //  	        <Permissions>integrationapi</Permissions>
  //  	        <ContactType>Primary</ContactType>
  //  	        <UCTReferer />
  //  	        <UCTIsCaptcha>false</UCTIsCaptcha>
  //  	        <UATReferer />
  //  	        <UATIsCaptcha>false</UATIsCaptcha>
  //  	        <Username>test@company.com</Username>
  //  	    </UserDetails>
  //  	    <AgentDetails>
  //  	        <AgentID>96592</AgentID>
  //  	        <AgentName>My Company</AgentName>
  //  	        <AccountNumber />
  //  	        <IATACode />
  //  	        <Address1>P.O. Box 555</Address1>
  //  	        <Address2 />
  //  	        <Place />
  //  	        <StateProvince>NC</StateProvince>
  //  	        <City>
  //  	            <Code>USBFO</Code>
  //  	            <Name>Raleigh</Name>
  //  	        </City>
  //  	        <Country>
  //  	            <Code>US</Code>
  //  	            <Name>US - United States</Name>
  //  	        </Country>
  //  	        <ZipCode>28522</ZipCode>
  //  	        <Email />
  //  	        <Phone />
  //  	        <Fax />
  //  	        <IsEAirwayBill>false</IsEAirwayBill>
  //  	        <EYProgram>false</EYProgram>
  //  	        <WhiteLabelMobileApp>false</WhiteLabelMobileApp>
  //  	        <Limits>
  //  	            <UCTSearchesRemaining />
  //  	            <UATSearchesRemaining />
  //  	            <AgentID>96592</AgentID>
  //  	        </Limits>
  //  	        <Permissions>integrationapi</Permissions>
  //  	    </AgentDetails>
  //  	    <UserPreferences>
  //  	        <AboutUs />
  //  	        <MOTD />
  //  	        <Language>en-US</Language>
  //  	        <Currency>USD</Currency>
  //  	        <UnitSystem>Metric</UnitSystem>
  //  	        <TimeZone>
  //  	            <TheID>450</TheID>
  //  	            <KeyIdentifier>TimeZone</KeyIdentifier>
  //  	            <KeyValue>GMT</KeyValue>
  //  	            <KeyDescription>(GMT-11:00)UTC-11</KeyDescription>
  //  	            <IsDefault>false</IsDefault>
  //  	        </TimeZone>
  //  	        <DateFormat>dd-MMM-yyyy</DateFormat>
  //  	        <TimeFormat>h:mm t</TimeFormat>
  //  	        <Controls />
  //  	        <ContactEmail />
  //  	    </UserPreferences>
  //  	    <Version>
  //  	        <APIVersion>3.4.0.0ah8</APIVersion>
  //  	        <UIVersion>3.1</UIVersion>
  //  	    </Version>
  //  	    <NumNonMSDBContacts />
  //  	</AuthResponseDTO>
  //  


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