Page 1 of 1

SSLClient connect to Website via Certificate

Posted: Thu 17 Nov 2016 14:18
by Matze87
Hi guys,

I try to connect to a website with sub directories and has to use a certifcate for authentication.

This function seems to work.
but if I change the Host to www.examples.com/test it throws an exception.

Is there any possibility to use subdirectories?


Code: Select all

procedure TForm3.btn1Click(Sender: TObject);
 var
  cert : TScCertificate;
  storage : TScFileStorage;
  client : TScSSLClient;
  i : Integer;
  b : boolean;
  certName : String;
  ciphers:TScSSLCipherSuites;
begin

  storage := TScFileStorage.Create(Self);
  client := TScSSLClient.Create(Self);
  try
    client.HostName := 'www.examples.com';
    client.Port := 443;
    storage.Path := 'C:\Certs\';


    certName := 'cert.cer';

    b := False;
    for i := 0 to storage.Certificates.Count - 1 do begin
      cert := storage.Certificates[i];
      if (cert.CertName = certName) then begin
        b := True;
      end;
    end;
    if (not b) then begin
      cert := TScCertificate.Create(storage.Certificates);
      cert.CertName := CertName;
      cert.ImportFrom(CertName);
      cert.Ready := True;
    end;

    client.Storage := storage;

    client.Connect;
    if (client.Connected) then begin
      client.IsSecure := True;
      ShowMessage ('Connected');
    end;
  except
    on E:Exception do begin
      ShowMessage (e.Message);
    end;
  end;
  client.Disconnect;
  client.Free;
  storage.Free;
end;
Thank you.

Re: SSLClient connect to Website via Certificate

Posted: Fri 18 Nov 2016 09:37
by ViktorV
The TScSSLClient.HostName property must contain an IP address or a domain name of the server which we connect to.
TScSSLClient is not used for working with HTTP protocol. To solve your issue, you should specify a subdirectory when working with HTTP protocol.