Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

Delphi DLL Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(Delphi DLL) Azure ServiceBus - Request a Token from ACS

This example duplicates the HTTP POST described at Request a Token from ACS.

Chilkat for Delphi Downloads

Chilkat non-ActiveX DLL for Delphi

Chilkat ActiveX DLL for Delphi

* The examples here use the non-ActiveX DLL.

uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Http, HttpRequest, HttpResponse;

...

procedure TForm1.Button1Click(Sender: TObject);
var
http: HCkHttp;
req: HCkHttpRequest;
useTls: Boolean;
resp: HCkHttpResponse;
accessToken: PWideChar;

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

// The goal of this example is to send the following HTTP POST:

// POST https://your-namespace-sb.accesscontrol.windows.net/WRAPv0.9/ HTTP/1.1  
// Content-Type: application/x-www-form-urlencoded  
// Host: your-namespace-sb.accesscontrol.windows.net  
// Content-Length: 136  
// Expect: 100-continue  
// Connection: Keep-Alive  
// 
// wrap_name=owner&wrap_password=r8LuxCKD6DWY8auQcFql4M7euH2UuhcLcV1TaJTqNNE%3d&wrap_scope=http%3a%2f%2fyour-namespace.servicebus.windows.net%2f
// 

http := CkHttp_Create();
req := CkHttpRequest_Create();

// Build the HTTP request...
CkHttpRequest_putHttpVerb(req,'POST');
CkHttpRequest_putPath(req,'/WRAPv0.9/');
CkHttpRequest_putContentType(req,'application/x-www-form-urlencoded');

// Adding the Connection: Keep-Alive is optional.  It only makes sense if the intent is to send
// additional requests to the same domain (your-namespace-sb.accesscontrol.windows.net) within a reasonable time period.
CkHttpRequest_AddHeader(req,'Connection','Keep-Alive');

// The Expect: 100-continue really isn't necessary.  This only makes sense when a response is large.  The "100-continue"
// provides a means for the HTTP server to alert the HTTP client that the request failed before sending the full response.
// In this case, the response size is small, so there's no real need to bother with an "Expect: 100-continue".
// If desired, it would be added just like any request header:
CkHttpRequest_AddHeader(req,'Expect','100-continue');

// Note: The following headers are automatically added by Chilkat:  Content-Type, Host, Content-Length.
// The application should NOT set these directly.

// Add the query parameters
// When URL decoded and split, the query params look like this:
// 
// 	wrap_name=owner
// 	wrap_password=r8LuxCKD6DWY8auQcFql4M7euH2UuhcLcV1TaJTqNNE=
// 	wrap_scope=http://your-namespace.servicebus.windows.net/

// Pass the URL-decoded values to AddParam.
CkHttpRequest_AddParam(req,'wrap_name','owner');
CkHttpRequest_AddParam(req,'wrap_password','r8LuxCKD6DWY8auQcFql4M7euH2UuhcLcV1TaJTqNNE=');
CkHttpRequest_AddParam(req,'wrap_scope','http://your-namespace.servicebus.windows.net/');

// OK.. our request is properly setup.  Now send to the web server at your-namespace-sb.accesscontrol.windows.net.
// We want https (i.e. SSL/TLS), so the port would be 443.
useTls := True;
resp := CkHttp_SynchronousRequest(http,'your-namespace-sb.accesscontrol.windows.net',443,useTls,req);
if (CkHttp_getLastMethodSuccess(http) <> True) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http));
    Exit;
  end;

// A successful response will have a status code = 200.
if (CkHttpResponse_getStatusCode(resp) <> 200) then
  begin
    Memo1.Lines.Add('Response Status Code = ' + IntToStr(CkHttpResponse_getStatusCode(resp)));
    Memo1.Lines.Add(CkHttpResponse__bodyStr(resp));
    Memo1.Lines.Add('Failed.');
    CkHttpResponse_Dispose(resp);
    Exit;
  end;

// A successful response will contain a URL encoded param string such as the following:

// 	wrap_access_token=net.windows.servicebus.action%3d
// 	Listen%252cManage%252cSend%26
// 	http%253a%252f%252fschemas.microsoft.com%252faccesscontrolservice%252f2010%252f07%252fclaims%252fidentityprovider%3d
// 	https%253a%252f%252fyour-namespace-sb.accesscontrol.windows.net%252f%26
// 	Audience%3dhttp%253a%252f%252fyour-namespace.servicebus.windows.net%252f%26
// 	ExpiresOn%3d1404435127%26
// 	Issuer%3dhttps%253a%252f%252fyour-namespace-sb.accesscontrol.windows.net%252f%26
// 	HMACSHA256%3dF%252bBoXUoifWdT%252fly8Oic9V1oPBbc3KmXKbSJbVhGSopU%253d&
// 	wrap_access_token_expires_in=10799
// 

// The UrlEncParamValue method can be used to extract individual param values by name.
// There are two params in the response: wrap_access_token and wrap_access_token_expires.
// (It's a bit confusing because the value of the wrap_access_token is itself a URL encoded 
// param string.)

// Get the access token from the response:
accessToken := CkHttpResponse__urlEncParamValue(resp,CkHttpResponse__bodyStr(resp),'wrap_access_token');

Memo1.Lines.Add('Your access token is the following param string:');
Memo1.Lines.Add(accessToken);

CkHttpResponse_Dispose(resp);

CkHttp_Dispose(http);
CkHttpRequest_Dispose(req);

end;

 

© 2000-2024 Chilkat Software, Inc. All Rights Reserved.