CINXE.COM
libcurl - source code examples
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>libcurl - source code examples</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"> <link rel="stylesheet" type="text/css" href="/curl.css"> <link rel="shortcut icon" href="/favicon.ico"> <link rel="icon" href="/logo/curl-symbol.svg" type="image/svg+xml"> <link rel="alternate" type="application/rss+xml" title="cURL Releases" href="https://github.com/curl/curl/releases.atom"> </head> <body> <div class="main"> <div class="menu"> <a href="/libcurl/c/libcurl.html" class="menuitem" title="Overview">API Overview</a> <div class="dropdown"> <a class="dropbtn" href="/libcurl/c/">Docs</a> <div class="dropdown-content"> <a href="/libcurl/c/libcurl-easy.html">API: easy</a> <a href="/libcurl/c/libcurl-multi.html">API: multi</a> <a href="/libcurl/c/libcurl-share.html">API: share</a> <a href="/libcurl/c/libcurl-url.html">API: URL</a> <a href="/libcurl/c/libcurl-ws.html">API: WebSocket</a> <a href="/libcurl/c/libcurl-env.html">Environment vars</a> <a href="/libcurl/c/libcurl-errors.html">Errors</a> <a href="/libcurl/c/example.html">Examples</a> <a href="/libcurl/security.html">Security</a> <a href="/libcurl/c/symbols-in-versions.html">Symbols</a> <a href="/libcurl/c/libcurl-tutorial.html">Tutorial</a> <hr> <a href="/libcurl/c/easy_setopt_options.html">easy setopt options</a> <a href="/libcurl/c/easy_getinfo_options.html">easy getinfo options</a> <a href="/libcurl/c/multi_setopt_options.html">multi setopt options</a> <a href="/libcurl/c/tls-options.html">TLS options</a> </div> </div> <div class="dropdown"> <a class="dropbtn" href="/libcurl/c/">Functions</a> <div class="dropdown-content"> <a href="/libcurl/c/allfuncs.html">All functions</a> <a href="/libcurl/c/curl_easy_getinfo.html">curl_easy_getinfo</a> <a href="/libcurl/c/curl_easy_init.html">curl_easy_init</a> <a href="/libcurl/c/curl_easy_perform.html">curl_easy_perform</a> <a href="/libcurl/c/curl_easy_reset.html">curl_easy_reset</a> <a href="/libcurl/c/curl_easy_setopt.html">curl_easy_setopt</a> <a href="/libcurl/c/curl_multi_add_handle.html">curl_multi_add_handle</a> <a href="/libcurl/c/curl_multi_init.html">curl_multi_init</a> <a href="/libcurl/c/curl_multi_perform.html">curl_multi_perform</a> <a href="/libcurl/c/curl_multi_remove_handle.html">curl_multi_remove_handle</a> <a href="/libcurl/c/curl_multi_setopt.html">curl_multi_setopt</a> </div> </div> </div> <div class="contents"> <div class="where"><a href="/">curl</a> / <a href="/libcurl/">libcurl</a> / <a href="/libcurl/c/">API</a> / <b>Examples</b></div> <h1> libcurl - small example snippets </h1> <div class="relatedbox"> <b>Related:</b> <br><a href="allfuncs.html">All functions</a> <br><a href="./">API</a> <br><a href="symbols-in-versions.html">Symbols</a> </div> <p> 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. <p align="center"> <span style="font-size: 140%; padding: 5px 5px 5px 5px; border: 4px dotted blue;" align="center"><a href="allexamples.zip"> Download all examples </a></span> <p> You can also see a list of all <a href="options-in-examples.html">libcurl easy options and which example source codes that use them</a>. <p> All examples are written in C, unless specifically mentioned. <h2> Index of examples </h2> <p> <table> <tr class="even"><td><a href="10-at-a-time.html">10-at-a-time</a> </td><td>Download many files in parallel, in the same thread.</td><tr class="odd"><td><a href="address-scope.html">address-scope</a> </td><td>HTTP GET to an IPv6 address with specific scope</td><tr class="even"><td><a href="altsvc.html">altsvc</a> </td><td>HTTP with Alt-Svc support</td><tr class="odd"><td><a href="anyauthput.html">anyauthput</a> </td><td>HTTP PUT upload with authentication using "any" method. libcurl picks the one the server supports/wants.</td><tr class="even"><td><a href="cacertinmem.html">cacertinmem</a> </td><td>CA cert in memory with OpenSSL to get an HTTPS page.</td><tr class="odd"><td><a href="certinfo.html">certinfo</a> </td><td>Extract lots of TLS certificate info.</td><tr class="even"><td><a href="chkspeed.html">chkspeed</a> </td><td>Show transfer timing info after download completes.</td><tr class="odd"><td><a href="connect-to.html">connect-to</a> </td><td>Use CURLOPT_CONNECT_TO to connect to "wrong" hostname</td><tr class="even"><td><a href="cookie_interface.html">cookie_interface</a> </td><td>Import and export cookies with COOKIELIST.</td><tr class="odd"><td><a href="crawler.html">crawler</a> </td><td>Web crawler based on curl and libxml2 to stress-test curl with hundreds of concurrent connections to various servers.</td><tr class="even"><td><a href="debug.html">debug</a> </td><td>Show how CURLOPT_DEBUGFUNCTION can be used.</td><tr class="odd"><td><a href="default-scheme.html">default-scheme</a> </td><td>Change default scheme when none is provided in the URL</td><tr class="even"><td><a href="ephiperfifo.html">ephiperfifo</a> </td><td>multi socket API usage with epoll and timerfd</td><tr class="odd"><td><a href="evhiperfifo.html">evhiperfifo</a> </td><td>multi socket interface together with libev</td><tr class="even"><td><a href="externalsocket.html">externalsocket</a> </td><td>Pass in a custom socket for libcurl to use.</td><tr class="odd"><td><a href="fileupload.html">fileupload</a> </td><td>Upload to a file:// URL</td><tr class="even"><td><a href="ftp-wildcard.html">ftp-wildcard</a> </td><td>FTP wildcard pattern matching</td><tr class="odd"><td><a href="ftpget.html">ftpget</a> </td><td>Get a single file from an FTP server.</td><tr class="even"><td><a href="ftpgetinfo.html">ftpgetinfo</a> </td><td>Checks a single file's size and mtime from an FTP server.</td><tr class="odd"><td><a href="ftpgetresp.html">ftpgetresp</a> </td><td>Similar to ftpget.c but also stores the received response-lines in a separate file using our own callback!</td><tr class="even"><td><a href="ftpsget.html">ftpsget</a> </td><td>Get a single file from an FTPS server.</td><tr class="odd"><td><a href="ftpupload.html">ftpupload</a> </td><td>Performs an FTP upload and renames the file just after a successful transfer.</td><tr class="even"><td><a href="ftpuploadfrommem.html">ftpuploadfrommem</a> </td><td>FTP upload a file from memory</td><tr class="odd"><td><a href="ftpuploadresume.html">ftpuploadresume</a> </td><td>Upload to FTP, resuming failed transfers. Active mode.</td><tr class="even"><td><a href="getinfo.html">getinfo</a> </td><td>Use getinfo to get content-type after completed transfer.</td><tr class="odd"><td><a href="getinmemory.html">getinmemory</a> </td><td>Shows how the write callback function can be used to download data into a chunk of memory instead of storing it in a file.</td><tr class="even"><td><a href="getredirect.html">getredirect</a> </td><td>Show how to extract Location: header and URL to redirect to.</td><tr class="odd"><td><a href="getreferrer.html">getreferrer</a> </td><td>Show how to extract referrer header.</td><tr class="even"><td><a href="ghiper.html">ghiper</a> </td><td>multi socket API usage together with glib2</td><tr class="odd"><td><a href="headerapi.html">headerapi</a> </td><td>Extract headers post transfer with the header API</td><tr class="even"><td><a href="hiperfifo.html">hiperfifo</a> </td><td>multi socket API usage with libevent 2</td><tr class="odd"><td><a href="href_extractor.html">href_extractor</a> </td><td>Uses the "Streaming HTML parser" to extract the href pieces in a streaming manner from a downloaded HTML.</td><tr class="even"><td><a href="hsts-preload.html">hsts-preload</a> </td><td>Preload domains to HSTS</td><tr class="odd"><td><a href="htmltidy.html">htmltidy</a> </td><td>Download a document and use libtidy to parse the HTML.</td><tr class="even"><td><a href="htmltitle.html">htmltitle</a> (C++)</td><td>Get a web page, extract the title with libxml.</td><tr class="odd"><td><a href="http-options.html">http-options</a> </td><td>Issue an HTTP 'OPTIONS *' request</td><tr class="even"><td><a href="http-post.html">http-post</a> </td><td>simple HTTP POST using the easy interface</td><tr class="odd"><td><a href="http2-download.html">http2-download</a> </td><td>Multiplexed HTTP/2 downloads over a single connection</td><tr class="even"><td><a href="http2-pushinmemory.html">http2-pushinmemory</a> </td><td>HTTP/2 server push. Receive all data in memory.</td><tr class="odd"><td><a href="http2-serverpush.html">http2-serverpush</a> </td><td>HTTP/2 server push</td><tr class="even"><td><a href="http2-upload.html">http2-upload</a> </td><td>Multiplexed HTTP/2 uploads over a single connection</td><tr class="odd"><td><a href="http3.html">http3</a> </td><td>Very simple HTTP/3 GET</td><tr class="even"><td><a href="http3-present.html">http3-present</a> </td><td>Checks if HTTP/3 support is present in libcurl.</td><tr class="odd"><td><a href="httpcustomheader.html">httpcustomheader</a> </td><td>HTTP request with custom modified, removed and added headers</td><tr class="even"><td><a href="httpput.html">httpput</a> </td><td>HTTP PUT with easy interface and read callback</td><tr class="odd"><td><a href="httpput-postfields.html">httpput-postfields</a> </td><td>HTTP PUT using CURLOPT_POSTFIELDS</td><tr class="even"><td><a href="https.html">https</a> </td><td>Simple HTTPS GET</td><tr class="odd"><td><a href="imap-append.html">imap-append</a> </td><td>Send email with IMAP</td><tr class="even"><td><a href="imap-authzid.html">imap-authzid</a> </td><td>Retrieve emails from a shared IMAP mailbox</td><tr class="odd"><td><a href="imap-copy.html">imap-copy</a> </td><td>Copy an email from one IMAP folder to another</td><tr class="even"><td><a href="imap-create.html">imap-create</a> </td><td>Create a new IMAP folder</td><tr class="odd"><td><a href="imap-delete.html">imap-delete</a> </td><td>Delete an IMAP folder</td><tr class="even"><td><a href="imap-examine.html">imap-examine</a> </td><td>Obtain information about an IMAP folder</td><tr class="odd"><td><a href="imap-fetch.html">imap-fetch</a> </td><td>Retrieve IMAP emails</td><tr class="even"><td><a href="imap-list.html">imap-list</a> </td><td>List the folders within an IMAP mailbox</td><tr class="odd"><td><a href="imap-lsub.html">imap-lsub</a> </td><td>List the subscribed IMAP folders</td><tr class="even"><td><a href="imap-multi.html">imap-multi</a> </td><td>Get IMAP email with the multi interface</td><tr class="odd"><td><a href="imap-noop.html">imap-noop</a> </td><td>Perform an IMAP noop</td><tr class="even"><td><a href="imap-search.html">imap-search</a> </td><td>Search for new IMAP emails</td><tr class="odd"><td><a href="imap-ssl.html">imap-ssl</a> </td><td>IMAP with implicit SSL</td><tr class="even"><td><a href="imap-store.html">imap-store</a> </td><td>Modify the properties of an email over IMAP</td><tr class="odd"><td><a href="imap-tls.html">imap-tls</a> </td><td>IMAP using TLS</td><tr class="even"><td><a href="interface.html">interface</a> </td><td>Use CURLOPT_INTERFACE to bind the outgoing socket to an interface</td><tr class="odd"><td><a href="ipv6.html">ipv6</a> </td><td>HTTPS GET using IPv6 only</td><tr class="even"><td><a href="keepalive.html">keepalive</a> </td><td>Use the TCP keep-alive options</td><tr class="odd"><td><a href="localport.html">localport</a> </td><td>Use CURLOPT_LOCALPORT to control local port number</td><tr class="even"><td><a href="maxconnects.html">maxconnects</a> </td><td>Set maximum number of persistent connections to 1.</td><tr class="odd"><td><a href="multi-app.html">multi-app</a> </td><td>A basic application source code using the multi interface doing two transfers in parallel.</td><tr class="even"><td><a href="multi-debugcallback.html">multi-debugcallback</a> </td><td>multi interface and debug callback</td><tr class="odd"><td><a href="multi-double.html">multi-double</a> </td><td>multi interface code doing two parallel HTTP transfers</td><tr class="even"><td><a href="multi-event.html">multi-event</a> </td><td>multi_socket API using libevent</td><tr class="odd"><td><a href="multi-formadd.html">multi-formadd</a> </td><td>using the multi interface to do a multipart formpost without blocking</td><tr class="even"><td><a href="multi-legacy.html">multi-legacy</a> </td><td>A basic application source code using the multi interface doing two transfers in parallel without curl_multi_wait/poll.</td><tr class="odd"><td><a href="multi-post.html">multi-post</a> </td><td>using the multi interface to do a multipart formpost without blocking</td><tr class="even"><td><a href="multi-single.html">multi-single</a> </td><td>using the multi interface to do a single download</td><tr class="odd"><td><a href="multi-uv.html">multi-uv</a> </td><td>multi_socket API using libuv</td><tr class="even"><td><a href="multithread.html">multithread</a> </td><td>A multi-threaded program using pthreads to fetch several files at once</td><tr class="odd"><td><a href="netrc.html">netrc</a> </td><td>Use credentials from .netrc</td><tr class="even"><td><a href="parseurl.html">parseurl</a> </td><td>Basic URL API use.</td><tr class="odd"><td><a href="persistent.html">persistent</a> </td><td>reusing handles to do HTTP persistent connections</td><tr class="even"><td><a href="pop3-authzid.html">pop3-authzid</a> </td><td>Retrieve emails from a shared POP3 mailbox</td><tr class="odd"><td><a href="pop3-dele.html">pop3-dele</a> </td><td>Delete POP3 emails</td><tr class="even"><td><a href="pop3-list.html">pop3-list</a> </td><td>List the contents of a POP3 mailbox</td><tr class="odd"><td><a href="pop3-multi.html">pop3-multi</a> </td><td>Get POP3 email using the multi interface</td><tr class="even"><td><a href="pop3-noop.html">pop3-noop</a> </td><td>Perform a POP3 noop</td><tr class="odd"><td><a href="pop3-retr.html">pop3-retr</a> </td><td>Retrieve POP3 email</td><tr class="even"><td><a href="pop3-ssl.html">pop3-ssl</a> </td><td>Get POP3 email using implicit SSL</td><tr class="odd"><td><a href="pop3-stat.html">pop3-stat</a> </td><td>Obtain POP3 message statistics</td><tr class="even"><td><a href="pop3-tls.html">pop3-tls</a> </td><td>POP3 using TLS</td><tr class="odd"><td><a href="pop3-top.html">pop3-top</a> </td><td>POP3 example showing how to retrieve only the headers of an email</td><tr class="even"><td><a href="pop3-uidl.html">pop3-uidl</a> </td><td>List the contents of a POP3 mailbox by unique ID</td><tr class="odd"><td><a href="post-callback.html">post-callback</a> </td><td>Issue an HTTP POST and provide the data through the read callback.</td><tr class="even"><td><a href="postinmemory.html">postinmemory</a> </td><td>Make an HTTP POST with data from memory and receive response in memory.</td><tr class="odd"><td><a href="postit2.html">postit2</a> </td><td>HTTP Multipart formpost with file upload and two additional parts.</td><tr class="even"><td><a href="postit2-formadd.html">postit2-formadd</a> </td><td>HTTP Multipart formpost with file upload and two additional parts.</td><tr class="odd"><td><a href="progressfunc.html">progressfunc</a> </td><td>Use the progress callbacks, old and/or new one depending on available libcurl version.</td><tr class="even"><td><a href="protofeats.html">protofeats</a> </td><td>Outputs all protocols and features supported</td><tr class="odd"><td><a href="range.html">range</a> </td><td>GET a range only of an HTTP resource</td><tr class="even"><td><a href="resolve.html">resolve</a> </td><td>Use CURLOPT_RESOLVE to feed custom IP addresses for given hostname + port number combinations.</td><tr class="odd"><td><a href="rtsp-options.html">rtsp-options</a> </td><td>Very simple RTSP request sending OPTIONS.</td><tr class="even"><td><a href="sendrecv.html">sendrecv</a> </td><td>Demonstrate curl_easy_send() and curl_easy_recv() usage.</td><tr class="odd"><td><a href="sepheaders.html">sepheaders</a> </td><td>Simple HTTP GET that stores the headers in a separate file</td><tr class="even"><td><a href="sessioninfo.html">sessioninfo</a> </td><td>Uses the CURLINFO_TLS_SESSION data.</td><tr class="odd"><td><a href="sftpget.html">sftpget</a> </td><td>Gets a file using an SFTP URL.</td><tr class="even"><td><a href="sftpuploadresume.html">sftpuploadresume</a> </td><td>Upload to SFTP, resuming a previously aborted transfer.</td><tr class="odd"><td><a href="shared-connection-cache.html">shared-connection-cache</a> </td><td>Connection cache shared between easy handles with the share interface</td><tr class="even"><td><a href="simple.html">simple</a> </td><td>Very simple HTTP GET</td><tr class="odd"><td><a href="simplepost.html">simplepost</a> </td><td>Very simple HTTP POST</td><tr class="even"><td><a href="simplessl.html">simplessl</a> </td><td>Shows HTTPS usage with client certs and optional ssl engine use.</td><tr class="odd"><td><a href="smooth-gtk-thread.html">smooth-gtk-thread</a> </td><td>A multi threaded application that uses a progress bar to show status. It uses Gtk+ to make a smooth pulse.</td><tr class="even"><td><a href="smtp-authzid.html">smtp-authzid</a> </td><td>Send email on behalf of another user with SMTP</td><tr class="odd"><td><a href="smtp-expn.html">smtp-expn</a> </td><td>Expand an SMTP email mailing list</td><tr class="even"><td><a href="smtp-mail.html">smtp-mail</a> </td><td>Send email with SMTP</td><tr class="odd"><td><a href="smtp-mime.html">smtp-mime</a> </td><td>Send SMTP mime emails</td><tr class="even"><td><a href="smtp-multi.html">smtp-multi</a> </td><td>Send SMTP email with the multi interface</td><tr class="odd"><td><a href="smtp-ssl.html">smtp-ssl</a> </td><td>Send SMTP email using implicit SSL</td><tr class="even"><td><a href="smtp-tls.html">smtp-tls</a> </td><td>Send SMTP email using implicit TLS</td><tr class="odd"><td><a href="smtp-vrfy.html">smtp-vrfy</a> </td><td>Verify an SMTP email address</td><tr class="even"><td><a href="sslbackend.html">sslbackend</a> </td><td>Shows HTTPS usage with client certs and optional ssl engine use.</td><tr class="odd"><td><a href="synctime.html">synctime</a> </td><td>Set your system time from a remote HTTP server's Date: header.</td><tr class="even"><td><a href="threaded-ssl.html">threaded-ssl</a> </td><td>Show the required mutex callback setups for GnuTLS and OpenSSL when using libcurl multi-threaded.</td><tr class="odd"><td><a href="unixsocket.html">unixsocket</a> </td><td>Access HTTP server over Unix domain socket</td><tr class="even"><td><a href="url2file.html">url2file</a> </td><td>Download a given URL into a local file named page.out.</td><tr class="odd"><td><a href="urlapi.html">urlapi</a> </td><td>Set working URL with CURLU *.</td><tr class="even"><td><a href="usercertinmem.html">usercertinmem</a> </td><td>Use an in-memory user certificate and RSA key and retrieve an https page.</td><tr class="odd"><td><a href="websocket.html">websocket</a> </td><td>WebSocket using CONNECT_ONLY</td><tr class="even"><td><a href="websocket-cb.html">websocket-cb</a> </td><td>WebSocket download-only using write callback</td><tr class="odd"><td><a href="xmlstream.html">xmlstream</a> </td><td>Stream-parse a document using the streaming Expat parser.</td></table> <p> You also find these examples in the distribution archive, in <a href="https://github.com/curl/curl/tree/master/docs/examples">docs/examples</a>. </div> </div> </body> </html>