Delphi DLL
Delphi DLL
Example: Http.CloseAllConnections method
See more HTTP Examples
Demonstrates how to call the CloseAllConnections method.Chilkat Delphi DLL Downloads
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, StringBuilder, Http;
...
procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
http: HCkHttp;
url: PWideChar;
sbJson: HCkStringBuilder;
statusCode: Integer;
begin
success := False;
http := CkHttp_Create();
// Demonstrate
url := 'https://finnhub.io/api/v1/quote?symbol={$symbol}&token={$api_key}';
// When the request is sent, the {$symbol} is replaced with "MSFT"
// and the {$api_key} is replaced with "1234567890ABCDEF"
CkHttp_SetUrlVar(http,'symbol','MSFT');
CkHttp_SetUrlVar(http,'api_key','1234567890ABCDEF');
sbJson := CkStringBuilder_Create();
success := CkHttp_QuickGetSb(http,url,sbJson);
if (success = False) then
begin
Memo1.Lines.Add(CkHttp__lastErrorText(http));
Exit;
end;
statusCode := CkHttp_getLastStatus(http);
Memo1.Lines.Add(CkHttp__lastResponseHeader(http));
// The response header contains this:
// Date: Tue, 19 Aug 2025 12:18:56 GMT
// Content-Type: application/json; charset=utf-8
// Transfer-Encoding: chunked
// Connection: keep-alive
// Content-Encoding: gzip
// The "Connection: keep-alive" header ensures the server keeps the connection open for subsequent requests.
// If the server responds with a "Connection: close" header, it indicates the connection will be closed after the response.
// Consequently, Chilkat will also close the connection, requiring a new one to be established for any subsequent requests to the same server.
// If your application uses the same HTTP object instance to send requests to a different server, a new connection will be established with that server.
// Existing connections remain open, with Chilkat maintaining up to 10 open connections.
// If all 10 connections are in use, Chilkat will close the least recently used connection to connect to a new server.
// Your application can explicitly close all open connections like this:
success := CkHttp_CloseAllConnections(http);
if (success = False) then
begin
Memo1.Lines.Add(CkHttp__lastErrorText(http));
Exit;
end;
Memo1.Lines.Add('Success.');
CkHttp_Dispose(http);
CkStringBuilder_Dispose(sbJson);
end;