Sample code for 30+ languages & platforms
Delphi ActiveX

REST through SOCKS Proxy

See more REST Examples

Demonstrates how to connect through a SOCKS proxy to make REST API calls.

Chilkat Delphi ActiveX Downloads

Delphi ActiveX
uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Chilkat_TLB;

...

procedure TForm1.Button1Click(Sender: TObject);
var
success: Integer;
rest: TChilkatRest;
socket: TChilkatSocket;
bTls: Integer;
port: Integer;
maxWaitMs: Integer;
authAws: TChilkatAuthAws;
responseXml: WideString;
xml: TChilkatXml;

begin
success := 0;

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

// This example connects to a REST server through a SOCKS proxy.
// It will connect to the Amazon AWS service for this example.
rest := TChilkatRest.Create(Self);
socket := TChilkatSocket.Create(Self);

// Set the SOCKS proxy domain or IP address, port, and SOCKS version number (4 or 5)
socket.SocksHostname := '192.168.1.100';
socket.SocksPort := 1080;
socket.SocksVersion := 5;
// Other properties exist for specifying a SOCKS proxy login and password,
// but these are not used in this example.

// Connect through the HTTP proxy to the Amazon AWS server for the S3 service.
bTls := 1;
port := 443;
maxWaitMs := 5000;
success := socket.Connect('s3.amazonaws.com',port,bTls,maxWaitMs);
if (success <> 1) then
  begin
    Memo1.Lines.Add('Connect Failure Error Code: ' + IntToStr(socket.ConnectFailReason));
    Memo1.Lines.Add(socket.LastErrorText);
    Exit;
  end;

// Use the proxied TLS connection:
success := rest.UseConnection(socket.ControlInterface,1);
if (success <> 1) then
  begin
    Memo1.Lines.Add(rest.LastErrorText);
    Exit;
  end;

// Provide AWS credentials for the REST call.
authAws := TChilkatAuthAws.Create(Self);
authAws.AccessKey := 'AWS_ACCESS_KEY';
authAws.SecretKey := 'AWS_SECRET_KEY';
authAws.ServiceName := 's3';
success := rest.SetAuthAws(authAws.ControlInterface);

// List all buckets for the account...
responseXml := rest.FullRequestNoBody('GET','/');
if (rest.LastMethodSuccess <> 1) then
  begin
    Memo1.Lines.Add(rest.LastErrorText);
    Exit;
  end;

xml := TChilkatXml.Create(Self);
success := xml.LoadXml(responseXml);

// Show the full XML returned.
Memo1.Lines.Add(xml.GetXml());

// Iterate over the buckets, showing each bucket name.
success := xml.FindChild2('Buckets');
if (xml.FirstChild2() = 1) then
  begin
    Memo1.Lines.Add(xml.GetChildContent('Name'));
    while (xml.NextSibling2() = 1) do
      begin
        Memo1.Lines.Add(xml.GetChildContent('Name'));
      end;

  end;
// Move the internal pointer back to the root node.
xml.GetRoot2();
end;