Sample code for 30+ languages & platforms
Delphi DLL

Disconnect from a REST Server

See more REST Examples

Demonstrates Rest.Disconnect, which closes the current HTTP connection. The argument is the maximum number of milliseconds to wait for the close to complete.

Background. Connections are normally kept alive for reuse. Disconnect is used when an application wants to explicitly release the connection rather than relying on keep-alive or object destruction.

Chilkat Delphi DLL Downloads

Delphi DLL
var
success: Boolean;
rest: HCkRest;
bTls: Boolean;
bAutoReconnect: Boolean;
responseText: PWideChar;
bDisconnected: Boolean;

begin
success := False;

rest := CkRest_Create();

//  Connect to the REST server.  The 3rd argument enables TLS (use 1 for HTTPS on port 443),
//  and the 4th enables automatic reconnection if the connection is dropped between requests.
bTls := True;
bAutoReconnect := True;
success := CkRest_Connect(rest,'example.com',443,bTls,bAutoReconnect);
if (success = False) then
  begin
    Memo1.Lines.Add(CkRest__lastErrorText(rest));
    Exit;
  end;

responseText := CkRest__fullRequestNoBody(rest,'GET','/api/status');
if (CkRest_getLastMethodSuccess(rest) = False) then
  begin
    Memo1.Lines.Add(CkRest__lastErrorText(rest));
    Exit;
  end;
Memo1.Lines.Add(responseText);

//  Close the connection.  The argument is the maximum number of milliseconds to wait for the
//  close to complete.
bDisconnected := CkRest_Disconnect(rest,200);
if (bDisconnected <> True) then
  begin
    Memo1.Lines.Add('The disconnect did not complete within the wait time.');
  end;
Memo1.Lines.Add('Done.');

CkRest_Dispose(rest);