A TLS connection needs a TLS engine: the component that holds the trust anchors, the client certificate if there is one, and the TLS options. The client components come in two tiers that differ only in who owns that engine.
TsmHTTPSClient - creates and owns an engine of its own, published as TLSServer. One component on the form, nothing to connect: the right choice for one client talking to one service.Advanced - TsmAdvancedHTTPSClient - uses an engine you place yourself, a TsmSimpleTLSInternalServer, named in its TLSServer property. Several clients can share one engine.Both do the same requests the same way: everything in Download a page over HTTPS applies to either.
ServerName to the name in the certificate - see Download a page over HTTPS.constructor tTwoServices.Create(const aCAFile, aOrdersHost, aStockHost: string; aPort: Integer); begin inherited Create; { One engine: the trust anchors (and, with mutual TLS, the client certificate) are set once, and what the engine learns - fetched revocation lists, for one - serves every client that uses it. } Engine := TsmSimpleTLSInternalServer.Create(nil); if Engine.LoadRootCertsFromFile(aCAFile) = 0 then raise eHTTPSClientError.CreateFmt('No certificate in %s', [aCAFile]); { Two clients, two servers, one engine. } Orders := TsmAdvancedHTTPSClient.Create(nil); Orders.TLSServer := Engine; Orders.Host := aOrdersHost; Orders.Port := aPort; Stock := TsmAdvancedHTTPSClient.Create(nil); Stock.TLSServer := Engine; Stock.Host := aStockHost; Stock.Port := aPort; end; destructor tTwoServices.Destroy; begin { The clients first, then the engine they use. } Orders.Free; Stock.Free; Engine.Free; inherited; end;
A TsmAdvancedHTTPSClient whose TLSServer is left empty uses the application-wide engine GlobalServer, and refuses to connect when there is none.
Drop a TsmSimpleTLSInternalServer and the clients, and pick the engine in each client's TLSServer property in the Object Inspector. To give that engine the public web roots, add a TsmCCADBTrustAnchors and set its Engine - see Choose which servers a client trusts.
TsmHTTPSClient · TsmAdvancedHTTPSClient · TsmSimpleTLSInternalServer · StreamSec.Mobile.HTTPSClient · StreamSec.Mobile.TlsInternalServer