Delphi DLL
Delphi DLL
Use an Existing Socket Connection for REST
See more REST Examples
Demonstrates Rest.UseConnection, which supplies an already-connected Socket as the transport for REST requests instead of calling Connect. This is useful when the connection must be established with specific socket options or shared across objects.
Background. Rest can operate over any connected socket. The second argument enables automatic reconnection so a dropped connection is transparently re-established between requests.
Chilkat Delphi DLL Downloads
var
success: Boolean;
socket: HCkSocket;
bSsl: Boolean;
rest: HCkRest;
bAutoReconnect: Boolean;
responseText: PWideChar;
begin
success := False;
// Demonstrates supplying an already-connected socket for the REST transport. This is useful when
// the connection must be established with specific socket options, or reused across objects.
socket := CkSocket_Create();
bSsl := True;
success := CkSocket_Connect(socket,'example.com',443,bSsl,5000);
if (success <> True) then
begin
Memo1.Lines.Add(CkSocket__lastErrorText(socket));
Exit;
end;
rest := CkRest_Create();
// Use the connected socket as the transport. The 2nd argument enables automatic reconnection.
bAutoReconnect := True;
success := CkRest_UseConnection(rest,socket,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);
CkSocket_Dispose(socket);
CkRest_Dispose(rest);