cURL / libcurl / API / Example Sources

libcurl - small example snippets

These files are intended as examples only. In the interest of simplicity and clarity, they might not include proper error handling and might produce compiler warnings on some platforms. Real-world applications should pay more attention to these issues.

Download allexamples.zip, it contains all the example sources listed here.

You can also see a list of all libcurl easy options and which example source codes that use them.

All examples are written in C, unless specifically mentioned.

The examples

10-at-a-time Source code using the multi interface to download many files, with a capped maximum amount of simultaneous transfers.
anyauthput HTTP PUT upload with authentiction using "any" method. libcurl picks the one the server supports/wants.
asiohiper (C++)demonstrate the use of multi socket interface with boost::asio
cacertinmem CA cert in memory with OpenSSL to get a HTTPS page.
certinfo Extract lots of TLS certificate info.
chkspeed Show transfer timing info after download completes.
cookie_interface Import and export cookies with COOKIELIST.
curlgtk use the libcurl in a gtk-threaded application
curlx demonstrates use of SSL context callback, requires OpenSSL
debug Show how CURLOPT_DEBUGFUNCTION can be used.
evhiperfifo multi socket interface together with libev
externalsocket An example demonstrating how an application can pass in a custom socket to libcurl to use. This example also handles the connect itself.
fileupload Upload to a file:// URL
fopen implements an fopen() abstraction allowing reading from URLs
ftp-wildcard FTP wildcard pattern matching
ftpget Get a single file from an FTP server.
ftpgetinfo Checks a single file's size and mtime from an FTP server.
ftpgetresp Similar to ftpget.c but also stores the received response-lines in a separate file using our own callback!
ftpsget Get a single file from an FTPS server.
ftpupload Performs an FTP upload and renames the file just after a successful transfer.
ftpuploadresume Upload to FTP, resuming failed transfers.
getinfo Use getinfo to get content-type after completed transfer.
getinmemory Shows how the write callback function can be used to download data into a chunk of memory instead of storing it in a file.
ghiper multi socket API usage together with with glib2
hiperfifo multi socket API usage with libevent 2
href_extractor Uses the "Streaming HTML parser" to extract the href pieces in a streaming manner from a downloaded HTML.
htmltidy Download a document and use libtidy to parse the HTML.
htmltitle (C++)Get a web page, extract the title with libxml.
http-post simple HTTP POST using the easy interface
http2-download Multiplexed HTTP/2 downloads over a single connection
http2-serverpush HTTP/2 server push
http2-upload Multiplexed HTTP/2 uploads over a single connection
httpcustomheader HTTP request with custom modified, removed and added headers
httpput HTTP PUT with easy interface and read callback
https Simple HTTPS GET
imap-append Simple IMAP APPEND use
imap-copy
imap-create
imap-delete
imap-examine
imap-fetch
imap-list
imap-lsub
imap-multi
imap-noop
imap-search
imap-ssl
imap-store
imap-tls
multi-app
multi-debugcallback multi interface and debug callback
multi-double multi interface code doing two parallel HTTP transfers
multi-post using the multi interface to do a multipart formpost without blocking
multi-single using the multi interface to do a single download
multi-uv multi_socket API using libuv
multithread A multi-threaded example that uses pthreads to fetch several files at once
opensslthreadlock one way to set the necessary OpenSSL locking callbacks if you want to do multi-threaded transfers with HTTPS/FTPS with libcurl built to use OpenSSL.
persistant re-using handles to do HTTP persistent connections
pop3-dele
pop3-list
pop3-multi
pop3-noop
pop3-retr
pop3-ssl
pop3-stat
pop3-tls
pop3-top
pop3-uidl
post-callback An example source code that issues a HTTP POST and we provide the actual data through a read callback.
postinmemory
postit2
progressfunc
resolve
rtsp
sampleconv
sendrecv
sepheaders
sessioninfo
sftpget
simple
simplepost
simplessl
smooth-gtk-thread
smtp-expn
smtp-mail
smtp-multi
smtp-ssl
smtp-tls
smtp-vrfy
synctime
threaded-ssl
url2file
usercertinmem
xmlstream

You also find these examples in the distribution archive, in docs/examples.