The all-purpose solution is Curl. The curl.exe program is part of current Windows versions. Links: GitHub, Download, Manual, libcurl C API and libcurl C examples. An encapsulation for libcurl DLL can be found in the mORMot unit mormot.lib.curl. The mORMot library does not need to be installed. Download the current commit and the static binaries from the last tag directory. Set the appropriate library and search paths in Delphi. This pattern helps to create them:
// Simply replace the colons with the save path
..\src;..\src\app;..\src\core;..\src\crypt;..\src\db;..\src\lib;..\src\misc;..\src\net;..\src\orm;..\src\rest;..\src\script;..\src\soa;..\src\tools\ecc;..\src\ui;
For many use cases you can find a template in the libcurl C examples. The following Delphi example shows the implementation for a download:
uses
mormot.core.base,
mormot.core.text,
mormot.core.os,
mormot.lib.curl;
var
hnd: TCurl;
url: RawUtf8;
res: TCurlResult;
buffer: RawByteString;
responseSize: Int64;
begin
if not CurlIsAvailable then Exit; //=>
hnd := curl.easy_init;
if hnd <> Nil then
begin
url := 'https://icons8.com/icons/set/home.html';
curl.easy_setopt(hnd, coURL, Pointer(url));
curl.easy_setopt(hnd, coSSLVerifyPeer, 0);
curl.easy_setopt(hnd, coSSLVerifyHost, 0);
curl.easy_setopt(hnd, coWriteFunction, @CurlWriteRawByteString);
curl.easy_setopt(hnd, coWriteData, @buffer);
res := curl.easy_perform(hnd);
if res = crOk then
begin
FileFromString(buffer, MakePath([Executable.ProgramFilePath, 'home.html']));
curl.easy_getinfo(hnd, ciSizeDownloadT, responseSize);
ShowMessage(Format('Download completed: %s', [KB(responseSize)]));
end
else
ShowMessage(Format('Curl told us %d (%s)', [Ord(res), curl.easy_strerror(res)]));
curl.easy_cleanup(hnd);
end;
end;
An example to study is also the class TCurlHttp from the unit mormot.net.client.
With best regards
Thomas