libcurl - small example snippets
A collection of smaller stand-alone applications using the libcurl API in different ways to show how to use it for different Internet transfer scenarios.
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.
Index of examples
10-at-a-time | Download many files in parallel, in the same thread. |
address-scope | HTTP GET to an IPv6 address with specific scope |
altsvc | HTTP with Alt-Svc support |
anyauthput | HTTP PUT upload with authentication using "any" method. libcurl picks the one the server supports/wants. |
cacertinmem | CA cert in memory with OpenSSL to get an HTTPS page. |
certinfo | Extract lots of TLS certificate info. |
chkspeed | Show transfer timing info after download completes. |
connect-to | Use CURLOPT_CONNECT_TO to connect to "wrong" hostname |
cookie_interface | Import and export cookies with COOKIELIST. |
crawler | Web crawler based on curl and libxml2 to stress-test curl with hundreds of concurrent connections to various servers. |
debug | Show how CURLOPT_DEBUGFUNCTION can be used. |
default-scheme | Change default scheme when none is provided in the URL |
ephiperfifo | multi socket API usage with epoll and timerfd |
evhiperfifo | multi socket interface together with libev |
externalsocket | Pass in a custom socket for libcurl to use. |
fileupload | Upload to a file:// URL |
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. |
ftpuploadfrommem | FTP upload a file from memory |
ftpuploadresume | Upload to FTP, resuming failed transfers. Active mode. |
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. |
getredirect | Show how to extract Location: header and URL to redirect to. |
getreferrer | Show how to extract referrer header. |
ghiper | multi socket API usage together with glib2 |
headerapi | Extract headers post transfer with the header API |
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. |
hsts-preload | Preload domains to HSTS |
htmltidy | Download a document and use libtidy to parse the HTML. |
htmltitle (C++) | Get a web page, extract the title with libxml. |
http-options | Issue an HTTP 'OPTIONS *' request |
http-post | simple HTTP POST using the easy interface |
http2-download | Multiplexed HTTP/2 downloads over a single connection |
http2-pushinmemory | HTTP/2 server push. Receive all data in memory. |
http2-serverpush | HTTP/2 server push |
http2-upload | Multiplexed HTTP/2 uploads over a single connection |
http3 | Very simple HTTP/3 GET |
http3-present | Checks if HTTP/3 support is present in libcurl. |
httpcustomheader | HTTP request with custom modified, removed and added headers |
httpput | HTTP PUT with easy interface and read callback |
httpput-postfields | HTTP PUT using CURLOPT_POSTFIELDS |
https | Simple HTTPS GET |
imap-append | Send email with IMAP |
imap-authzid | Retrieve emails from a shared IMAP mailbox |
imap-copy | Copy an email from one IMAP folder to another |
imap-create | Create a new IMAP folder |
imap-delete | Delete an IMAP folder |
imap-examine | Obtain information about an IMAP folder |
imap-fetch | Retrieve IMAP emails |
imap-list | List the folders within an IMAP mailbox |
imap-lsub | List the subscribed IMAP folders |
imap-multi | Get IMAP email with the multi interface |
imap-noop | Perform an IMAP noop |
imap-search | Search for new IMAP emails |
imap-ssl | IMAP with implicit SSL |
imap-store | Modify the properties of an email over IMAP |
imap-tls | IMAP using TLS |
interface | Use CURLOPT_INTERFACE to bind the outgoing socket to an interface |
ipv6 | HTTPS GET using IPv6 only |
keepalive | Use the TCP keep-alive options |
localport | Use CURLOPT_LOCALPORT to control local port number |
maxconnects | Set maximum number of persistent connections to 1. |
multi-app | A basic application source code using the multi interface doing two transfers in parallel. |
multi-debugcallback | multi interface and debug callback |
multi-double | multi interface code doing two parallel HTTP transfers |
multi-event | multi_socket API using libevent |
multi-formadd | using the multi interface to do a multipart formpost without blocking |
multi-legacy | A basic application source code using the multi interface doing two transfers in parallel without curl_multi_wait/poll. |
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 program using pthreads to fetch several files at once |
netrc | Use credentials from .netrc |
parseurl | Basic URL API use. |
persistent | reusing handles to do HTTP persistent connections |
pop3-authzid | Retrieve emails from a shared POP3 mailbox |
pop3-dele | Delete POP3 emails |
pop3-list | List the contents of a POP3 mailbox |
pop3-multi | Get POP3 email using the multi interface |
pop3-noop | Perform a POP3 noop |
pop3-retr | Retrieve POP3 email |
pop3-ssl | Get POP3 email using implicit SSL |
pop3-stat | Obtain POP3 message statistics |
pop3-tls | POP3 using TLS |
pop3-top | POP3 example showing how to retrieve only the headers of an email |
pop3-uidl | List the contents of a POP3 mailbox by unique ID |
post-callback | Issue an HTTP POST and provide the data through the read callback. |
postinmemory | Make an HTTP POST with data from memory and receive response in memory. |
postit2 | HTTP Multipart formpost with file upload and two additional parts. |
postit2-formadd | HTTP Multipart formpost with file upload and two additional parts. |
progressfunc | Use the progress callbacks, old and/or new one depending on available libcurl version. |
protofeats | Outputs all protocols and features supported |
range | GET a range only of an HTTP resource |
resolve | Use CURLOPT_RESOLVE to feed custom IP addresses for given hostname + port number combinations. |
rtsp-options | Very simple RTSP request sending OPTIONS. |
sendrecv | Demonstrate curl_easy_send() and curl_easy_recv() usage. |
sepheaders | Simple HTTP GET that stores the headers in a separate file |
sessioninfo | Uses the CURLINFO_TLS_SESSION data. |
sftpget | Gets a file using an SFTP URL. |
sftpuploadresume | Upload to SFTP, resuming a previously aborted transfer. |
shared-connection-cache | Connection cache shared between easy handles with the share interface |
simple | Very simple HTTP GET |
simplepost | Very simple HTTP POST |
simplessl | Shows HTTPS usage with client certs and optional ssl engine use. |
smooth-gtk-thread | A multi threaded application that uses a progress bar to show status. It uses Gtk+ to make a smooth pulse. |
smtp-authzid | Send email on behalf of another user with SMTP |
smtp-expn | Expand an SMTP email mailing list |
smtp-mail | Send email with SMTP |
smtp-mime | Send SMTP mime emails |
smtp-multi | Send SMTP email with the multi interface |
smtp-ssl | Send SMTP email using implicit SSL |
smtp-tls | Send SMTP email using implicit TLS |
smtp-vrfy | Verify an SMTP email address |
sslbackend | Shows HTTPS usage with client certs and optional ssl engine use. |
synctime | Set your system time from a remote HTTP server's Date: header. |
threaded-ssl | Show the required mutex callback setups for GnuTLS and OpenSSL when using libcurl multi-threaded. |
unixsocket | Access HTTP server over Unix domain socket |
url2file | Download a given URL into a local file named page.out. |
urlapi | Set working URL with CURLU *. |
usercertinmem | Use an in-memory user certificate and RSA key and retrieve an https page. |
websocket | WebSocket using CONNECT_ONLY |
websocket-cb | WebSocket download-only using write callback |
xmlstream | Stream-parse a document using the streaming Expat parser. |
You also find these examples in the distribution archive, in docs/examples.