Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Clickatell Send SMS Text Message using HTTP GET
See more Clickatell Examples
Demonstrate how to send a Clickatell SMS text message using an HTTP GET request with query params.Chilkat Pascal (Lazarus/Delphi) Downloads
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.JsonObject;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
http: THttp;
queryParams: TJsonObject;
resp: THttpResponse;
begin
success := False;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http := THttp.Create;
// Implements the following CURL command:
// curl -G https://api.clickatell.com/http/sendmsg \
// -d "api_id=xxxx" \
// -d "user=yourUsername" \
// -d "password=yourPassword" \
// -d "from=yourFromPhoneNumber" \
// -d "to=receiverPhoneNumber" \
// -d "text=The text of your message"
// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code
queryParams := TJsonObject.Create;
queryParams.UpdateString('api_id','xxxx');
queryParams.UpdateString('user','yourUsername');
queryParams.UpdateString('password','yourPassword');
queryParams.UpdateString('from','yourFromPhoneNumber');
queryParams.UpdateString('to','receiverPhoneNumber');
queryParams.UpdateString('text','The text of your message');
// If the following URL does not work, then try "https://api.clickatell.com/http/sendmsg"
resp := THttpResponse.Create;
success := http.HttpParams('GET','https://platform.clickatell.com/messages/http/send',queryParams,resp);
if (success = False) then
begin
WriteLn(http.LastErrorText);
Exit;
end;
WriteLn(resp.StatusCode);
WriteLn(resp.BodyStr);
http.Free;
queryParams.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.