Delphi Internet Development with Synapse

Introduction

Along with Indy and ICS, Synapse, is one of the most use open-source set of Internet components. It supports HTTP, SMTP, ICMP, etc. Support is available through the Synapse mailing list (archives), and a wiki. Unlike most Internet libraries out there, Synapse works synchronously, making development easier.

Setup

  1. Downlooad and unzip the latest source code into the directory of your choice, eg. C:\SYNAPSE
  2. Open the Delphi IDE, click on Tools > Env't Options > Library, and add C:\SYNAPSE\LIB to the Library Path
  3. Create a new project, and add the ad hoc Synapse unit to the Uses clause, eg. Uses httpsend,synacode;

Getting a web page

Here's how to connect to a web server and sending formatted data with a GET call:

uses
  SysUtils,Classes,httpsend,synacode;
 
var
  sl : TStringList;
  i : Integer;
  data : String;
 
begin
  //Must encode input to take care of non-authorized characters
  data := 'name=' + ParamStr(1);
  data := data + '&' + 'number=' + ParamStr(2);
  data := data + '&' + 'date=' + ParamStr(3);
  data := data + '&' + 'time=' + ParamStr(4);
  data := EncodeURL(data);
  WriteLn(data);
  
  sl := TStringList.Create;
  with THTTPSend.Create do
  begin
    if HttpGetText('http://localhost/put.php?' + data,sl) then
    try
      for i := 0 to sl.Count-1 do
        WriteLn(sl[i]);
    except
      WriteLn('Cannot get');
    end;
    sl.Free;
    Free;
  end;
end.

Resources