Articles libcurl and Delphi by Darian Miller

emailx45

Местный
Регистрация
5 Май 2008
Сообщения
3,571
Реакции
2,438
Credits
573
libcurl and Delphi
Darian Miller - Dec/2019
[SHOWTOGROUPS=4,20]
Для просмотра ссылки Войди или Зарегистрируйся is a hugely popular tool, available on most platforms and supports many internet protocols.

I've mainly used it for HTTP GET/POST tasks but there's built-in support for FTP, IMAP, POP3, SMTP, Gopher, RTMP, Telnet and more.

It can handle proxies, cookies and various authentication options.

In short, it's a deep toolbox that is extremely handy to use on a command line and is widely regarded as one of the most popular system tools of all time.

libcurl has a C API which is free and opensource. On their Для просмотра ссылки Войди или Зарегистрируйся, they currently list three options for Delphi developers:
file.png
ec6db6_bc40531d82ae4636a64a988eafbcb6ef~mv2.webp



curl4delphi
Let's get a test project using the latest project up and running. The first thing to do is to grab a copy of the curl4delphi repo, either download it directly from GitHub with your browser or fire up your favorite Git client and clone: Для просмотра ссылки Войди или Зарегистрируйся

You'll also want to grab the latest version of curl for Windows, which is currently version 7.67.0. Для просмотра ссылки Войди или Зарегистрируйсяand you'll use the included libcurl.dll or libcurl-x64.dll file found in the bin folder, depending if you are using 32 or 64-bit projects. Also copy the curl-ca-bundle.crt file or grab the very latest Для просмотра ссылки Войди или Зарегистрируйся which is also available on curl's website. (These are the same cert files, just with different names.)

This download will also get you the latest curl.exe to play with. Note that on my updated Windows 10 machine, the included curl.exe (found in windows\system32 and also in windows\sysWOW64) is an older version 7.55.1 which dates back to August 9, 2017. It's seemingly great that Microsoft started including curl in Windows 10 as of insider build 17063/update 1803, but you would think they would keep the tools provided in their System folders up to date. Just be aware of which version of curl.exe you are using (to be sure, run: curl.exe --version)

Next, you'll need the OpenSSL binaries which are available on the same download page. Again, download the 32-bit or 64-bit version based on your requirements. You'll need the libcrypto-1_1.dll and libssl1-1_1.dll files for 32-bit or the libcrypto-1_1-x64.dll and libssl-1_1-x64.dll files found in the root folder of the downloaded zip file.

Either put these required dependencies into a folder that is in your system PATH, or put them in the same folder as your application's executable. Also note further dependencies are available on the download page including Для просмотра ссылки Войди или Зарегистрируйся, Для просмотра ссылки Войди или Зарегистрируйся, Для просмотра ссылки Войди или Зарегистрируйся, and Для просмотра ссылки Войди или Зарегистрируйся. (ZLib support is built-in and is not required as a separate DLL.)

For now, the DLLs for libcurl, libssl, and libcrypto should be all that we need to fire up a sample project and download something from the web.

Start your Delphi (version XE2 or later) and load one of the easy sample projects included by curl4delphi such as: Examples\Easy_Http\Readme\Readme.dproj

When you build this project (note that the Windows 64-bit platform is selected by default) you will get the HTML source downloaded from Для просмотра ссылки Войди или Зарегистрируйся (If you get an error, ensure the dependencies are in the output folder.)

You can also load another example project from Examples\Misc\Version\Version.dproj and see the capabilities of your curl library. It should appear something like:

ec6db6_ce86c66cb3444f17baf1b7e07dad6e2d~mv2.webp



For something a bit more interesting, try the HTTPS demo provided in Examples\Raw_Http\Https\Https.dproj. You'll need the previously mentioned cacert.pem or curl-ca-bundle.crt files for this to work. This is the original code from the HTTP demo:

To use the cert bundle provided within the curl download, change the source line to reflect curl-ca-bundle.crt and perhaps change the example URL being used, and you should have a working https example download:

In a few minutes, with little effort, you have access for a wide variety of curl actions directly from your Delphi applications - including full TLS support. Thank you, Mikhail!

For further reading, curl has a page dedicated to Для просмотра ссылки Войди или Зарегистрируйся to review. You can also review a blog entry covering Для просмотра ссылки Войди или Зарегистрируйся when using the -servername argument with OpenSSL to generate a server's PEM file.

If you are debugging connectivity and you want to skip the certificate validation routines, you can set a curl option during testing - see the following working example using this same HTTPS example project:


License review
When dealing with third party components you should always review the license files. libcurl has a pretty broad Для просмотра ссылки Войди или Зарегистрируйся, making it available for use in your commercial projects. If you have Для просмотра ссылки Войди или Зарегистрируйся reviewing the decision, you can provide them with a partial list of Для просмотра ссылки Войди или Зарегистрируйся. The list is quite impressive - including Apple, Google, Facebook, Samsung, Cisco and many others.

As stated in his GitHub repo, the license for curl4delphi is MIT for the source and Public Domain for the examples so you shouldn't have a problem there either. While at GitHub, check out the Для просмотра ссылки Войди или Зарегистрируйся which includes a Для просмотра ссылки Войди или Зарегистрируйся and notes on Для просмотра ссылки Войди или Зарегистрируйся.

Summary
curl4delphi is seemingly a little-known wrapper for libcurl as it currently has only 23 stars on GitHub. It offers unique Unicode support and grants your Delphi XE2+ applications access to a host of functionality from the famous libcurl library. Given the liberal MIT license, you are free to use this functionality in your commercial applications. Clone it from GitHub today - and while you are there, click the Star button to let Mikhail and others know of your support!

Update: Arnaud Bouchez stopped by the blog and commented about libcurl support in Для просмотра ссылки Войди или Зарегистрируйся. I ran some quick tests it and it's fairly easy to get started. I added a Для просмотра ссылки Войди или Зарегистрируйся to show three different HTTP clients in mORMot, including a libcurl version. mORMot is a large project and there are a lot of hidden gems included. I'll probably add some more demos to that new GitHub repo as I discover more.


[/SHOWTOGROUPS]