libcurl-video-tutorials

Video tutorials for how to write internet clients using libcurl

View on GitHub

prev: setup table of contents next: receive data

Video

Youtube: libcurl video tutorial: simplest

simplest possible HTTPS client code

We go through the basics of the libcurl API and concepts and create the simplest possible HTTP client code we can.

mycurlapp.c first declares a CURL * handle and then calls curl_easy_init() to create one.

If the handle gets created successfullly, the function calls curl_easy_setopt() for that handle, sets the second argument to CURLOPT_URL and the exact URL to transfer in the third argument. https://example.com to be exact.

Once the URL has been set for the handle, the example performs the transfer by calling curl_easy_perform() and passing in the handle as argument. The perform function returns an error code in a CURLcode type that the function recevies in the variable named res.

If res isn’t CURLE_OK the transfer failed somehow and the program outputs an eror message and produces a text version from the error code by calling curl_easy_strerror() with the error code as argument.

Finally, it cleans up the handle again by calling curl_easy_cleanup() and passin in the handle as argument.

Ultimately, the function returns a zero.

setup

Using the Makefile from the setup episode, we build the program and test it.