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

Web API Categories

ASN.1
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
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
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
REST
REST Misc
RSA
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(Delphi DLL) Adding Cookies to an HTTP Request

Demonstrates how to add one or more cookies to an HTTP request. For Chilkat HTTP methods that use an HTTP request object, such as SynchronousRequest or PostUrlEncoded, cookies are added by calling the AddHeader method on the request object. For Chilkat HTTP methods that do not use an HTTP request object, such as QuickGetStr, cookies are added by calling AddQuickHeader.

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;
resp: HCkHttpResponse;
domain: PWideChar;
port: Integer;
ssl: Boolean;
success: Boolean;
html: PWideChar;

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

http := CkHttp_Create();

// The Cookie header field has this format:
// Cookie: name1=value1 [; name2=value2] ...

// Build an HTTP POST request:
req := CkHttpRequest_Create();
CkHttpRequest_SetFromUrl(req,'http://www.chilkatsoft.com/echoPost.asp');
CkHttpRequest_putHttpVerb(req,'POST');

CkHttpRequest_AddParam(req,'param1','value1');
CkHttpRequest_AddParam(req,'param2','value2');

// To add cookies to any HTTP request sent by a Chilkat HTTP method
// that uses an HTTP request object, add the cookies to the
// request object by calling AddHeader.  

// Add two cookies:
CkHttpRequest_AddHeader(req,'Cookie','user="mary"; city="Chicago"');

// Send the HTTP POST.  
// (The cookies are sent as part of the HTTP header.)

domain := 'www.chilkatsoft.com';
port := 80;
ssl := False;
resp := CkHttp_SynchronousRequest(http,domain,port,ssl,req);
if (CkHttp_getLastMethodSuccess(http) <> True) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http));
    Exit;
  end;

// Display the HTML body of the response.
if (CkHttpResponse_getStatusCode(resp) = 200) then
  begin
    // Show the last HTTP request header sent, which should include
    // our cookies...
    Memo1.Lines.Add(CkHttp__lastHeader(http));
  end
else
  begin
    Memo1.Lines.Add('HTTP Response Status = ' + IntToStr(CkHttpResponse_getStatusCode(resp)));
  end;

CkHttpResponse_Dispose(resp);

Memo1.Lines.Add('---------------------');

// Some Chilkat HTTP methods do not use an HTTP request object. 
// For these methods, such as for QuickGetStr, cookies (or any HTTP request header) 
// are added by calling AddQuickHeader.  
success := CkHttp_AddQuickHeader(http,'Cookie','user="mary"; city="Chicago"');

html := CkHttp__quickGetStr(http,'http://www.w3.org/');
if (CkHttp_getLastMethodSuccess(http) <> True) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http));
  end
else
  begin
    // Show the last HTTP request header sent, which should include
    // our cookies...
    Memo1.Lines.Add(CkHttp__lastHeader(http));
  end;

CkHttp_Dispose(http);
CkHttpRequest_Dispose(req);

end;

 

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