Search code examples
delphilistenerhttpserverdelphi-11-alexandria

Creating a local HTTP listener in Delphi


I have a windows desktop app written in Delphi 11 that I am integrating with Xero accounting. The first step is complete, which is using ShellExecute to open a browser with a generated url that gives the user the chance to login. A parameter of the url used is a redirect uri which includes a port.

How can I create a local http listener in Delphi 11 that will receive the data sent back by Xero?


Solution

  • Create a new application, drop a TIdHTTPServer component on it (or create it in code), set its Active property to True, and implement its OnCommandGet method, for example like this:

    procedure TForm1.IdHTTPServer1CommandGet(AContext: TIdContext;
      ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
    begin
      ShowMessage(ARequestInfo.URI);
    end;