libcurl初体验

  |   0 评论   |   0 浏览

背景

curl是c下面涉及到ssl的http上传下载库的第一选择。官方提供了一些示例,因此上手非常的容易。

官方示例

例子描述
10-at-a-timeDownload many files in parallel, in the same thread.
altsvcHTTP with Alt-Svc support
anyauthputHTTP 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
cacertinmemCA cert in memory with OpenSSL to get a HTTPS page.
certinfoExtract lots of TLS certificate info.
chkspeedShow transfer timing info after download completes.
cookie_interfaceImport and export cookies with COOKIELIST.
crawlerWeb crawler based on curl and libxml2 to stress-test curl with hundreds of concurrent connections to various servers.
curlgtkuse the libcurl in a gtk-threaded application
curlxdemonstrates use of SSL context callback, requires OpenSSL
debugShow how CURLOPT_DEBUGFUNCTION can be used.
ephiperfifomulti socket API usage with epoll and timerfd
evhiperfifomulti socket interface together with libev
externalsocketAn example demonstrating how an application can pass in a custom socket to libcurl to use. This example also handles the connect itself.
fileuploadUpload to a file:// URL
fopenimplements an fopen() abstraction allowing reading from URLs
ftp-wildcardFTP wildcard pattern matching
ftpgetGet a single file from an FTP server.
ftpgetinfoChecks a single file's size and mtime from an FTP server.
ftpgetrespSimilar to ftpget.c but also stores the received response-lines in a separate file using our own callback!
ftpsgetGet a single file from an FTPS server.
ftpuploadPerforms an FTP upload and renames the file just after a successful transfer.
ftpuploadfrommemFTP upload a file from memory
ftpuploadresumeUpload to FTP, resuming failed transfers.
getinfoUse getinfo to get content-type after completed transfer.
getinmemoryShows how the write callback function can be used to download data into a chunk of memory instead of storing it in a file.
getredirectShow how to extract Location: header and URL to redirect to.
ghipermulti socket API usage together with with glib2
hiperfifomulti socket API usage with libevent 2
href_extractorUses the "Streaming HTML parser" to extract the href pieces in a streaming manner from a downloaded HTML.
htmltidyDownload a document and use libtidy to parse the HTML.
htmltitle (C++)Get a web page, extract the title with libxml.
http-postsimple HTTP POST using the easy interface
http2-downloadMultiplexed HTTP/2 downloads over a single connection
http2-pushinmemoryHTTP/2 server push. Receive all data in memory.
http2-serverpushHTTP/2 server push
http2-uploadMultiplexed HTTP/2 uploads over a single connection
http3Very simple HTTP/3 GET
http3-presentChecks if HTTP/3 support is present in libcurl.
httpcustomheaderHTTP request with custom modified, removed and added headers
httpputHTTP PUT with easy interface and read callback
httpsSimple HTTPS GET
imap-appendIMAP example showing how to send e-mails
imap-authzidIMAP example showing how to retreieve e-mails from a shared mailed box
imap-copyIMAP example showing how to copy an e-mail from one folder to another
imap-createIMAP example showing how to create a new folder
imap-deleteIMAP example showing how to delete a folder
imap-examineIMAP example showing how to obtain information about a folder
imap-fetchIMAP example showing how to retreieve e-mails
imap-listIMAP example to list the folders within a mailbox
imap-lsubIMAP example to list the subscribed folders
imap-multiIMAP example using the multi interface
imap-noopIMAP example showing how to perform a noop
imap-searchIMAP example showing how to search for new e-mails
imap-sslIMAP example using SSL
imap-storeIMAP example showing how to modify the properties of an e-mail
imap-tlsIMAP example using TLS
multi-appA basic application source code using the multi interface doing two transfers in parallel.
multi-debugcallbackmulti interface and debug callback
multi-doublemulti interface code doing two parallel HTTP transfers
multi-eventmulti_socket API using libevent
multi-formaddusing the multi interface to do a multipart formpost without blocking
multi-pollsingle download with the multi interface's curl_multi_poll
multi-postusing the multi interface to do a multipart formpost without blocking
multi-singleusing the multi interface to do a single download
multi-uvmulti_socket API using libuv
multithreadA multi-threaded example that uses pthreads to fetch several files at once
opensslthreadlockone 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.
parseurlBasic URL API use.
persistentre-using handles to do HTTP persistent connections
pop3-authzidPOP3 example showing how to retrieve e-mails from a shared mailbox
pop3-delePOP3 example showing how to delete e-mails
pop3-listPOP3 example to list the contents of a mailbox
pop3-multiPOP3 example using the multi interface
pop3-noopPOP3 example showing how to perform a noop
pop3-retrPOP3 example showing how to retrieve e-mails
pop3-sslPOP3 example using SSL
pop3-statPOP3 example showing how to obtain message statistics
pop3-tlsPOP3 example using TLS
pop3-topPOP3 example showing how to retrieve only the headers of an e-mail
pop3-uidlPOP3 example to list the contents of a mailbox by unique ID
post-callbackIssue an HTTP POST and provide the data through the read callback.
postinmemoryMake a HTTP POST with data from memory and receive response in memory.
postit2HTTP Multipart formpost with file upload and two additional parts.
postit2-formaddHTTP Multipart formpost with file upload and two additional parts.
progressfuncUse the progress callbacks, old and/or new one depending on available libcurl version.
resolveUse CURLOPT_RESOLVE to feed custom IP addresses for given host name + port number combinations.
rtspA basic RTSP transfer
sampleconvThis is a simple example showing how a program on a non-ASCII platform would invoke callbacks to do its own codeset conversions instead of using the built-in iconv functions in libcurl.
sendrecvAn example of curl_easy_send() and curl_easy_recv() usage.
sepheadersSimple HTTP GET that stores the headers in a separate file
sessioninfoUses the CURLINFO_TLS_SESSION data.
sftpgetGets a file using an SFTP URL.
sftpuploadresumeUpload to SFTP, resuming a previously aborted transfer.
shared-connection-cacheConnection cache shared between easy handles with the share interface
simpleVery simple HTTP GET
simplepostVery simple HTTP POST
simplesslShows HTTPS usage with client certs and optional ssl engine use.
smooth-gtk-threadA multi threaded application that uses a progress bar to show status. It uses Gtk+ to make a smooth pulse.
smtp-authzidSend e-mail on behalf of another user with SMTP
smtp-expnSMTP example showing how to expand an e-mail mailing list
smtp-mailSend e-mail with SMTP
smtp-mimeSMTP example showing how to send mime e-mails
smtp-multiSMTP example using the multi interface
smtp-sslSMTP example using SSL
smtp-tlsSMTP example using TLS
smtp-vrfySMTP example showing how to verify an e-mail address
sslbackendShows HTTPS usage with client certs and optional ssl engine use.
synctimeSet your system time from a remote HTTP server's Date: header.
threaded-shared-connMulti-threaded transfers sharing a single connection pool
threaded-sslShow the required mutex callback setups for GnuTLS and OpenSSL when using libcurl multi-threaded.
url2fileDownload a given URL into a local file named page.out.
urlapiSet working URL with CURLU *.
usercertinmemUse an in-memory user certificate and RSA key and retrieve an https page.
xmlstreamStream-parse a document using the streaming Expat parser.