Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

Delphi DLL Examples

ASN.1
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
Facebook
FileAccess
Firebase
GMail REST API
GeoOp
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Google Sheets
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)
Jira
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
PayPal
Peoplevox
QuickBooks
REST
REST Misc
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Shopify
Socket/SSL/TLS
Spider
Stream
Stripe
SugarCRM
Tar Archive
Twitter
Upload
VoiceBase
Walmart
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Xero
Zip
curl
eBay

 

 

 

(Delphi DLL) HTTP Authentication (Basic, NTLM, Digest, Negotiate/Kerberos)

Demonstrates how to use HTTP authentication. Authentication can be added to any method that sends an HTTP request to the server, such as SynchronousRequest, QuickGetStr, PostXml, etc. To add authentication, simply set the Login and Password properties.

By default, Chilkat will use basic HTTP authentication, which sends the login/password clear-text over the connection. This is bad if SSL/TLS (i.e. HTTPS) is not used. However, if the connection is secure, there should be nothing wrong with using basic authentication.

Chilkat supports more secure authentication types as well, including Digest, NTLM, and Negotiate (which dynamically chooses between NTLM and Kerberos). To use Digest authentication, simply set the DigestAuth property = True. To use NTLM authentication, set the NtlmAuth property = True. Likewise, to use Negotiate authentication, set the NegotiateAuth property = True.

Important: Negotiate authentication is only supported for the Chilkat implementations that run on the Windows platform. This is because it is implemented internally using Microsoft's SSPI API. NTLM authentication however, is available for all supported operating systems because Chilkat implements NTLM directlly (i.e. does not use Microsoft SSPI for the underlying implementation.)

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;

...

procedure TForm1.Button1Click(Sender: TObject);
var
http: HCkHttp;
success: Boolean;
html: PWideChar;
http2: HCkHttp;
http3: HCkHttp;

begin
http := CkHttp_Create();

//  Any string unlocks the component for the 1st 30-days.
success := CkHttp_UnlockComponent(http,'Anything for 30-day trial');
if (success <> True) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http));
    Exit;
  end;

//  Set the Login and Password properties for authentication.
CkHttp_putLogin(http,'chilkat');
CkHttp_putPassword(http,'myPassword');

html := CkHttp__quickGetStr(http,'http://localhost/xyz.html');
//  Note:
if (CkHttp_getLastMethodSuccess(http) <> True) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http));
    Exit;
  end;

//  Examine the HTTP status code returned.
//  A status code of 401 is typically returned for "access denied";
//  if no login/password is provided, or if the credentials (login/password)
//  are incorrect.
Memo1.Lines.Add('HTTP status code for Basic authentication: ' + IntToStr(CkHttp_getLastStatus(http)));

//  Examine the HTML returned for the URL:
Memo1.Lines.Add(html);

http2 := CkHttp_Create();

//  To use NTLM authentication, set the
//  NtlmAuth property = True
CkHttp_putNtlmAuth(http2,True);

//  The session log can be captured to a file by
//  setting the SessionLogFilename property:
CkHttp_putSessionLogFilename(http2,'ntlmAuthLog.txt');

//  Examination of the HTTP session log will show the NTLM
//  back-and-forth exchange between the client and server.

//  This call will now use NTLM authentication (assuming it
//  is supported by the web server).
html := CkHttp__quickGetStr(http2,'http://localhost/xyz.html');
//  Note:
if (CkHttp_getLastMethodSuccess(http2) <> True) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http2));
    Exit;
  end;

Memo1.Lines.Add('HTTP status code for NTLM authentication: ' + IntToStr(CkHttp_getLastStatus(http2)));

http3 := CkHttp_Create();

//  To use Digest Authentication, set the DigestAuth property = True
//  Also, no more than one of the authentication type properties
//  (NtlmAuth, DigestAuth, and NegotiateAuth)  should be set
//  to True.
CkHttp_putDigestAuth(http3,True);

CkHttp_putSessionLogFilename(http3,'digestAuthLog.txt');

//  This call will now use Digest authentication (assuming it
//  is supported by the web server).
html := CkHttp__quickGetStr(http3,'http://localhost/xyz.html');
//  Note:
if (CkHttp_getLastMethodSuccess(http3) <> True) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http3));
    Exit;
  end;

Memo1.Lines.Add('HTTP status code for Digest authentication: ' + IntToStr(CkHttp_getLastStatus(http3)));

CkHttp_Dispose(http);
CkHttp_Dispose(http2);
CkHttp_Dispose(http3);

end;

 

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