How to establish a secure connection by using Synapse?

浪尽此生 提交于 2019-11-30 18:51:50

Yes it is; you can use one of the plugins shipped with Synapse. As it's also mentioned there, the best is to use the ssl_openssl.pas. If you decide to follow this one you will need except Sysapse also the OpenSSL library. Author recommends OpenSSL 0.9.7 but as he said on our local forum it seems to works also with OpenSSL 1.0.0d.

Note if you are using D2009 up you will need a Unicode support which is not fully supported in version. Download the latest version instead.

The following sample code receives first 1024 bytes as a response to the HTTP GET method of a secured website using SSL encryption. I've used for it OpenSSL 0.9.8h with the latest version of Synapse. Note you need to put libssl32.dll and libeay32.dll from the OpenSSL package into your output directory to make it work properly. Let's have a form with a button and memo where we receive a result.

uses blcksock, synautil, synsock, ssl_openssl, ssl_openssl_lib;

procedure TForm1.Button1Click(Sender: TObject);
var Socket: TTCPBlockSocket;

begin
  Socket := TTCPBlockSocket.Create;

  try
    Socket.Connect('www.yousendit.com', '443'); // connect to the host
    Socket.SSLDoConnect; // start SSL connection; only server has a certificate

    if Socket.LastError = 0 then
      begin
        Socket.SendString('GET' + CRLF); // request GET method
        Memo1.Text := Socket.RecvBufferStr(1024, 1000); // receive 1024 bytes
      end;

  finally
    Socket.Free;
  end;
end;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!