cURL

curl's project page on SourceForge.net

Sponsors:
Haxx

cURL > libcurl > API > Example Source Codes

libcurl - small example snippets

All Examples

Written in C unless specifically mentioned:

10-at-a-time
anyauthput
asiohiper (C++)
cacertinmem
certinfo
chkspeed
cookie_interface
curlgtk
curlx
debug
evhiperfifo
externalsocket
fileupload
fopen
ftp-wildcard
ftpget
ftpgetinfo
ftpgetresp
ftpsget
ftpupload
ftpuploadresume
getinfo
getinmemory
ghiper
hiperfifo
href_extractor
htmltidy
htmltitle (C++)
http-post
httpcustomheader
httpput
https
imap-append
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-double
multi-post
multi-single
multi-uv
multithread
opensslthreadlock
persistant
pop3-dele
pop3-list
pop3-multi
pop3-noop
pop3-retr
pop3-ssl
pop3-stat
pop3-tls
pop3-top
pop3-uidl
post-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

We're gathering libcurl example source codes here. Please submit yours!

NOTE: 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.

allexamples.zip contains all the example sources, some 90+ separate stand-alone files.

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

Some of the Examples

simple HTTP
simple.c shows how to get a remote web page in only four libcurl function calls.

simple HTTPS
https.c gets a single HTTPS page, while simplessl.c shows how to get a remote https page and a set of various SSL-controlling options.

get HTTP with headers separate
sepheader.c gets a web page and stores the response-headers in a separate file.

simple FTP
ftpget.c proves that getting a FTP file is just as simple.

FTP upload
ftpupload.c uploads a local file to a remote FTP server. It also renames the file after succcessful transfer.

get a remote file in memory only
getinmemory.c describes how you can use the callback system to fetch documents into a ram buffer with no file writing necessary.

HTTP PUT
httpput.c makes PUTs a local file to a HTTP server.

HTTP form POST
postit2.c shows how to build a RFC1867-style form post and send it to a HTTP server.

persistant transfers
persistant.c shows that just getting files in a sequential manner will make it use persistant connections if the remote server supports it.

multithreaded URL fetches
multithread.c starts a number of threads and retrieves one URL in each thread. This requires a working thread library.

URL fetch with GTK progress bar
curlgtk.c uses GTK and the libcurl progress callback to show a GUI progress bar while downloading.

fopen() URL
fopen.c shows how you could write an fopen()-style emulation layer to easily make your program read URLs instead of local files.

nonblocking multipart formpost
multi-post.c makes a multipart formpost using the multi interface, which makes it a non-blocking operation.

debug callback
debug.c shows how you can use the debug callback to get a full trace of all protocol data being sent/received (and more).

HTML parsing
htmltitle.cc shows how to use libxml to parse HTML retrieved with libcurl.

Using CURLOPT_SSL_CTX_FUNCTION
curlx.c uses CURLOPT_SSL_CTX_FUNCTION to set a custom callback to deal with an OpenSSL SSL_CTX * at SSL handshake time.

Doing SOAP with libcurl
SOAP example by vivtek.com

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

donate! Page updated July 05, 2014.
web site info

File upload with ASP.NET