docs/libcurl: improve easy setopt examples

- always assign the curl_easy_perform() return code (and declare
  the necessary 'result' variable for it)

- always call curl_easy_cleanup() on the created easy handles

Closes #21364
This commit is contained in:
Daniel Stenberg 2026-04-18 22:51:16 +02:00
parent 1cc683c859
commit 54ded66618
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
123 changed files with 413 additions and 145 deletions

View file

@ -54,11 +54,13 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_ABSTRACT_UNIX_SOCKET, "/tmp/foo.sock");
curl_easy_setopt(curl, CURLOPT_URL, "http://localhost/");
/* Perform the request */
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -48,12 +48,14 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/path/file");
/* wait no more than 5 seconds for the FTP server to connect */
curl_easy_setopt(curl, CURLOPT_ACCEPTTIMEOUT_MS, 5000L);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -106,13 +106,15 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
/* enable all supported built-in compressions */
curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, "");
/* Perform the request */
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -64,9 +64,11 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_ALTSVC_CTRL, CURLALTSVC_H1);
curl_easy_setopt(curl, CURLOPT_ALTSVC, "altsvc-cache.txt");
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -84,9 +84,11 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_ALTSVC_CTRL, CURLALTSVC_H1);
curl_easy_setopt(curl, CURLOPT_ALTSVC, "altsvc-cache.txt");
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -44,12 +44,13 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/dir/to/newfile");
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
curl_easy_setopt(curl, CURLOPT_APPEND, 1L);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -88,6 +88,7 @@ int main(void)
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL,
"https://service.region.example.com/uri");
curl_easy_setopt(curl, CURLOPT_AWS_SIGV4, "provider1:provider2");
@ -98,7 +99,8 @@ int main(void)
"provider1:provider2:region:service");
curl_easy_setopt(curl, CURLOPT_USERPWD, "MY_ACCESS_KEY:MY_SECRET_KEY");
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -69,9 +69,10 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
curl_easy_setopt(curl, CURLOPT_CAINFO, "/etc/certs/cabundle.pem");
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}

View file

@ -60,17 +60,17 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode res;
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
/* only reuse certificate stores for a short time */
curl_easy_setopt(curl, CURLOPT_CA_CACHE_TIMEOUT, 60L);
res = curl_easy_perform(curl);
result = curl_easy_perform(curl);
/* in this second request, the cache is not used if more than
sixty seconds passed since the previous connection */
res = curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}

View file

@ -62,13 +62,15 @@ int main(void)
{
struct priv myown;
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
/* call this function to close sockets */
curl_easy_setopt(curl, CURLOPT_CLOSESOCKETFUNCTION, closesocket);
curl_easy_setopt(curl, CURLOPT_CLOSESOCKETDATA, &myown);
/* call this function to close sockets */
curl_easy_setopt(curl, CURLOPT_CLOSESOCKETFUNCTION, closesocket);
curl_easy_setopt(curl, CURLOPT_CLOSESOCKETDATA, &myown);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -73,13 +73,15 @@ int main(void)
{
struct priv myown;
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
/* call this function to close sockets */
curl_easy_setopt(curl, CURLOPT_CLOSESOCKETFUNCTION, closesocket);
curl_easy_setopt(curl, CURLOPT_CLOSESOCKETDATA, &myown);
/* call this function to close sockets */
curl_easy_setopt(curl, CURLOPT_CLOSESOCKETFUNCTION, closesocket);
curl_easy_setopt(curl, CURLOPT_CLOSESOCKETDATA, &myown);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -69,12 +69,14 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
/* complete connection within 10 seconds */
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10L);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -70,12 +70,14 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
/* complete connection within 10000 milliseconds */
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT_MS, 10000L);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -96,10 +96,11 @@ int main(void)
curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_CONNECT_TO, connect_to);
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
curl_easy_perform(curl);
result = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);

View file

@ -76,11 +76,13 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
curl_easy_setopt(curl, CURLOPT_COOKIE, "tool=curl; fun=yes;");
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -92,6 +92,7 @@ int main(void)
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
/* my_cookie is imported immediately via CURLOPT_COOKIELIST. */
curl_easy_setopt(curl, CURLOPT_COOKIELIST, my_cookie);
@ -109,7 +110,7 @@ int main(void)
*/
curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "cookies.txt"); /* export */
curl_easy_perform(curl); /* cookies imported from cookies.txt */
result = curl_easy_perform(curl); /* cookies imported from cookies.txt */
curl_easy_cleanup(curl); /* cookies exported to cookies.txt */
}

View file

@ -62,6 +62,7 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
char local_buffer[1024]="data to send";
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
@ -71,7 +72,8 @@ int main(void)
/* send data from the local stack */
curl_easy_setopt(curl, CURLOPT_COPYPOSTFIELDS, local_buffer);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -68,6 +68,7 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
/* set a URL without a scheme */
curl_easy_setopt(curl, CURLOPT_URL, "example.com");
@ -75,7 +76,8 @@ int main(void)
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
/* Perform the request */
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -48,11 +48,12 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
curl_easy_setopt(curl, CURLOPT_DISALLOW_USERNAME_IN_URL, 1L);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -56,10 +56,11 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
curl_easy_setopt(curl, CURLOPT_DNS_SHUFFLE_ADDRESSES, 1L);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);

View file

@ -69,6 +69,7 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
curl_easy_setopt(curl, CURLOPT_DOH_URL,
@ -77,7 +78,8 @@ int main(void)
/* Disable hostname verification of the DoH server */
curl_easy_setopt(curl, CURLOPT_DOH_SSL_VERIFYHOST, 0L);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -81,6 +81,7 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
curl_easy_setopt(curl, CURLOPT_DOH_URL,
@ -89,7 +90,8 @@ int main(void)
/* Disable certificate verification of the DoH server */
curl_easy_setopt(curl, CURLOPT_DOH_SSL_VERIFYPEER, 0L);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -56,6 +56,7 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
curl_easy_setopt(curl, CURLOPT_DOH_URL,
@ -64,7 +65,8 @@ int main(void)
/* Ask for OCSP stapling when verifying the DoH server */
curl_easy_setopt(curl, CURLOPT_DOH_SSL_VERIFYSTATUS, 1L);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -79,9 +79,11 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
curl_easy_setopt(curl, CURLOPT_DOH_URL, "https://dns.example.com");
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -96,8 +96,10 @@ int main(void)
"ecl:AED+DQA87wAgACB/RuzUCsW3uBbSFI7mzD63TUXpI8sGDTnFTbFCDpa+" \
"CAAEAAEAAQANY292ZXIuZGVmby5pZQAA";
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_ECH, config);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -46,12 +46,14 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
/* wait 3 seconds for 100-continue */
curl_easy_setopt(curl, CURLOPT_EXPECT_100_TIMEOUT_MS, 3000L);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -62,12 +62,14 @@ int main(void)
struct local_stuff local_data;
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "ftp://ftp.example.com/file*");
curl_easy_setopt(curl, CURLOPT_WILDCARDMATCH, 1L);
curl_easy_setopt(curl, CURLOPT_FNMATCH_FUNCTION, my_fnmatch);
curl_easy_setopt(curl, CURLOPT_FNMATCH_DATA, &local_data);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -71,11 +71,13 @@ int main(void)
struct local_stuff local_data;
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "ftp://ftp.example.com/file*");
curl_easy_setopt(curl, CURLOPT_WILDCARDMATCH, 1L);
curl_easy_setopt(curl, CURLOPT_FNMATCH_FUNCTION, my_fnmatch);
curl_easy_setopt(curl, CURLOPT_FNMATCH_DATA, &local_data);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -138,12 +138,14 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
/* example.com is redirected, so we tell libcurl to follow redirection */
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -50,12 +50,14 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
CURLcode result2;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
curl_easy_setopt(curl, CURLOPT_FORBID_REUSE, 1L);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
/* this second transfer may not reuse the same connection */
curl_easy_perform(curl);
result2 = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}

View file

@ -52,10 +52,11 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
curl_easy_setopt(curl, CURLOPT_FRESH_CONNECT, 1L);
/* this transfer must use a new connection, not reuse an existing */
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}

View file

@ -106,10 +106,13 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
/* Set the timeout to 300 milliseconds */
curl_easy_setopt(curl, CURLOPT_HAPPY_EYEBALLS_TIMEOUT_MS, 300L);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);

View file

@ -63,11 +63,13 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
curl_easy_setopt(curl, CURLOPT_HEADER, 1L);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -68,6 +68,7 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
struct my_info my = { 10, "the cookies are in the cupboard" };
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
@ -76,7 +77,9 @@ int main(void)
/* pass in custom data to the callback */
curl_easy_setopt(curl, CURLOPT_HEADERDATA, &my);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -118,11 +118,14 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, header_callback);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -86,8 +86,11 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
curl_easy_setopt(curl, CURLOPT_HSTS, "/home/user/.hsts-cache");
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -48,18 +48,29 @@ struct MyData {
void *custom;
};
static CURLSTScode hsts_cb(CURL *easy, struct curl_hstsentry *sts,
void *clientp)
{
/* populate the struct as documented */
return CURLSTS_OK;
}
int main(void)
{
CURL *curl = curl_easy_init();
struct MyData this;
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
/* pass pointer that gets passed in to the
CURLOPT_HSTSREADFUNCTION callback */
curl_easy_setopt(curl, CURLOPT_HSTSREADDATA, &this);
/* set HSTS read callback */
curl_easy_setopt(curl, CURLOPT_HSTSREADFUNCTION, hsts_cb);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -90,6 +90,8 @@ int main(void)
struct priv my_stuff;
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
/* set HSTS read callback */
curl_easy_setopt(curl, CURLOPT_HSTSREADFUNCTION, hsts_cb);

View file

@ -53,13 +53,15 @@ int main(void)
CURL *curl = curl_easy_init();
struct MyData this;
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
/* pass pointer that gets passed in to the
CURLOPT_HSTSWRITEFUNCTION callback */
curl_easy_setopt(curl, CURLOPT_HSTSWRITEDATA, &this);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -64,8 +64,13 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
/* enable HSTS */
curl_easy_setopt(curl, CURLOPT_HSTS_CTRL, CURLHSTS_ENABLE);
curl_easy_perform(curl);
/* specify where to store the HSTS cache */
curl_easy_setopt(curl, CURLOPT_HSTS, "/home/user/.hsts-cache");
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -61,14 +61,16 @@ int main(void)
CURL *curl = curl_easy_init();
if(curl) {
struct curl_slist *list;
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
list = curl_slist_append(NULL, "ICY 200 OK");
list = curl_slist_append(list, "WEIRDO 99 FINE");
curl_easy_setopt(curl, CURLOPT_HTTP200ALIASES, list);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_slist_free_all(list); /* free the list again */
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -52,13 +52,15 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
/* use a GET to fetch this */
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
/* Perform the request */
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -169,6 +169,7 @@ int main(void)
struct curl_slist *list = NULL;
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
/* add this header */
@ -182,9 +183,10 @@ int main(void)
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_slist_free_all(list); /* free the list */
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -84,8 +84,9 @@ int main(void)
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
curl_formfree(formpost);

View file

@ -59,10 +59,12 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/file.txt");
curl_easy_setopt(curl, CURLOPT_PROXY, "http://127.0.0.1:80");
curl_easy_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, 1L);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -55,12 +55,14 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
/* we know the server is silly, ignore content-length */
curl_easy_setopt(curl, CURLOPT_IGNORE_CONTENT_LENGTH, 1L);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -63,6 +63,7 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
long uploadsize = FILE_SIZE;
curl_easy_setopt(curl, CURLOPT_URL,
@ -72,7 +73,8 @@ int main(void)
curl_easy_setopt(curl, CURLOPT_INFILESIZE, uploadsize);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -59,6 +59,7 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_off_t uploadsize = FILE_SIZE;
curl_easy_setopt(curl, CURLOPT_URL,
@ -68,7 +69,8 @@ int main(void)
curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, uploadsize);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -56,10 +56,12 @@ int main(void)
struct local rtp_data;
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_INTERLEAVEFUNCTION, rtp_write);
curl_easy_setopt(curl, CURLOPT_INTERLEAVEDATA, &rtp_data);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -53,12 +53,14 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
/* only allow 30 seconds idle time */
curl_easy_setopt(curl, CURLOPT_MAXAGE_CONN, 30L);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -57,12 +57,14 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
/* only allow each connection to be reused for 30 seconds */
curl_easy_setopt(curl, CURLOPT_MAXLIFETIME_CONN, 30L);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -50,6 +50,7 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
/* enable redirect following */
@ -59,7 +60,8 @@ int main(void)
curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 3L);
/* Perform the request */
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -55,6 +55,7 @@ int main(void)
if(curl) {
curl_mime *multipart = curl_mime_init(curl);
if(multipart) {
CURLcode result;
curl_mimepart *part = curl_mime_addpart(multipart);
curl_mime_name(part, "name");
curl_mime_data(part, "daniel", CURL_ZERO_TERMINATED);
@ -68,9 +69,10 @@ int main(void)
/* Set the form info */
curl_easy_setopt(curl, CURLOPT_MIMEPOST, multipart);
curl_easy_perform(curl); /* post away */
result = curl_easy_perform(curl); /* post away */
curl_mime_free(multipart); /* free the post data */
}
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -68,6 +68,7 @@ int main(void)
curl_mime *form = NULL;
if(curl) {
CURLcode result = CURLE_OK;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
curl_easy_setopt(curl, CURLOPT_MIME_OPTIONS, CURLMIMEOPT_FORMESCAPE);
@ -81,7 +82,7 @@ int main(void)
curl_easy_setopt(curl, CURLOPT_MIMEPOST, form);
/* Perform the request */
curl_easy_perform(curl);
result = curl_easy_perform(curl);
}
}

View file

@ -59,13 +59,15 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
/* get us the resource without a body - use HEAD */
curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);
/* Perform the request */
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -46,13 +46,15 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
/* enable progress meter */
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
/* Perform the request */
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -76,13 +76,15 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
/* accept various URLs */
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
/* use this proxy */
curl_easy_setopt(curl, CURLOPT_PROXY, "http://proxy.example:80");
/* ... but make sure this hostname is not proxied */
curl_easy_setopt(curl, CURLOPT_NOPROXY, "www.example.com");
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -60,12 +60,14 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL,
"https://example.com/../../etc/password");
curl_easy_setopt(curl, CURLOPT_PATH_AS_IS, 1L);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -66,6 +66,7 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
curl_easy_setopt(curl, CURLOPT_PINNEDPUBLICKEY, "/etc/publickey.der");
/* OR
@ -76,7 +77,8 @@ int main(void)
*/
/* Perform the request */
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -84,6 +84,7 @@ NULL
/* send an application/x-www-form-urlencoded POST */
int main(void)
{
CURLcode result = CURLE_OK;
CURL *curl = curl_easy_init();
if(curl) {
const char *data = "data to send";
@ -96,7 +97,8 @@ int main(void)
/* pass in a pointer to the data - libcurl does not copy */
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
/* send an application/json POST */
@ -115,7 +117,8 @@ int main(void)
/* pass in a pointer to the data - libcurl does not copy */
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -51,6 +51,7 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
const char *data = "data to send";
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
@ -60,7 +61,8 @@ int main(void)
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -51,6 +51,7 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
const char *data = large_chunk;
curl_off_t length_of_data = 12345; /* set somehow */
@ -61,7 +62,8 @@ int main(void)
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -61,6 +61,7 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
/* a silly POST example */
@ -70,7 +71,8 @@ int main(void)
302 and 303 HTTP response codes */
curl_easy_setopt(curl, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -58,9 +58,11 @@ int main(void)
struct priv prereq_data;
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_PREREQFUNCTION, prereq_callback);
curl_easy_setopt(curl, CURLOPT_PREREQDATA, &prereq_data);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -111,9 +111,11 @@ int main(void)
struct priv prereq_data;
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_PREREQFUNCTION, prereq_callback);
curl_easy_setopt(curl, CURLOPT_PREREQDATA, &prereq_data);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -70,10 +70,12 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/file.txt");
curl_easy_setopt(curl, CURLOPT_PRE_PROXY, "socks4://socks-proxy:1080");
curl_easy_setopt(curl, CURLOPT_PROXY, "http://proxy:80");
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -50,16 +50,19 @@ int main(void)
CURL *curl = curl_easy_init();
struct private secrets;
if(curl) {
CURLcode result;
struct private *extracted;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
/* store a pointer to our private struct */
curl_easy_setopt(curl, CURLOPT_PRIVATE, &secrets);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
/* we can extract the private pointer again too */
curl_easy_getinfo(curl, CURLINFO_PRIVATE, &extracted);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -61,13 +61,15 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
struct progress data;
/* pass struct to callback */
curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &data);
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -109,11 +109,13 @@ int main(void)
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
/* pass struct to callback */
curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &data);
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -86,6 +86,7 @@ int main(int argc, char **argv)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
/* pass in the URL from an external source */
curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
@ -94,7 +95,8 @@ int main(int argc, char **argv)
CURLPROTO_HTTP | CURLPROTO_TFTP | CURLPROTO_SFTP);
/* Perform the request */
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -69,6 +69,7 @@ int main(int argc, char **argv)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
/* pass in the URL from an external source */
curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
@ -76,7 +77,8 @@ int main(int argc, char **argv)
curl_easy_setopt(curl, CURLOPT_PROTOCOLS_STR, "http,tftp,sftp");
/* Perform the request */
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -136,9 +136,11 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/file.txt");
curl_easy_setopt(curl, CURLOPT_PROXY, "http://proxy.example:80");
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -61,6 +61,7 @@ int main(void)
struct curl_slist *list;
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
curl_easy_setopt(curl, CURLOPT_PROXY, "http://proxy.example.com:80");
@ -69,9 +70,10 @@ int main(void)
curl_easy_setopt(curl, CURLOPT_PROXYHEADER, list);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_slist_free_all(list); /* free the list again */
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -66,6 +66,7 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
curl_easy_setopt(curl, CURLOPT_PROXY, "https://proxy.example:443");
curl_easy_setopt(curl, CURLOPT_PROXY_PINNEDPUBLICKEY,
@ -74,7 +75,8 @@ int main(void)
"Gxa2eg7fRbEgoChTociMee9wno=");
/* Perform the request */
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -102,13 +102,15 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
/* ask libcurl to use TLS version 1.0 or later */
curl_easy_setopt(curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
/* Perform the request */
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -74,12 +74,14 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
/* Set the default value: strict name check please */
curl_easy_setopt(curl, CURLOPT_PROXY_SSL_VERIFYHOST, 2L);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -76,12 +76,14 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
/* Set the default value: strict certificate check please */
curl_easy_setopt(curl, CURLOPT_PROXY_SSL_VERIFYPEER, 1L);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -55,9 +55,13 @@ static size_t read_cb(char *ptr, size_t size, size_t nmemb, void *userdata)
int main(void)
{
CURL *curl = curl_easy_init();
CURL *curl;
FILE *src = fopen("local-file", "r");
if(!src)
return 1;
curl = curl_easy_init();
if(curl) {
FILE *src = fopen("local-file", "r");
CURLcode result;
curl_off_t fsize = 123456; /* set this to the size of the input file */
/* we want to use our own read function */
@ -76,8 +80,10 @@ int main(void)
curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)fsize);
/* Now run off and do what you have been told */
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
fclose(src);
}
~~~

View file

@ -73,13 +73,15 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
/* get the first 200 bytes */
curl_easy_setopt(curl, CURLOPT_RANGE, "0-199");
/* Perform the request */
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -57,13 +57,15 @@ int main(void)
CURL *curl = curl_easy_init();
struct MyData this;
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
/* pass pointer that gets passed in to the
CURLOPT_READFUNCTION callback */
curl_easy_setopt(curl, CURLOPT_READDATA, &this);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -91,6 +91,7 @@ int main(int argc, char **argv)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
/* pass in the URL from an external source */
curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
@ -99,7 +100,8 @@ int main(int argc, char **argv)
CURLPROTO_HTTP | CURLPROTO_HTTPS);
/* Perform the request */
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -75,6 +75,7 @@ int main(int argc, char **argv)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
/* pass in the URL from an external source */
curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
@ -82,7 +83,8 @@ int main(int argc, char **argv)
curl_easy_setopt(curl, CURLOPT_REDIR_PROTOCOLS_STR, "http,https");
/* Perform the request */
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -51,12 +51,14 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
/* tell it where we found the link to this place */
curl_easy_setopt(curl, CURLOPT_REFERER, "https://example.org/me.html");
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -53,6 +53,7 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/*");
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "OPTIONS");
@ -60,7 +61,8 @@ int main(void)
curl_easy_setopt(curl, CURLOPT_REQUEST_TARGET, "*");
/* Perform the request */
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -96,10 +96,11 @@ int main(void)
curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_RESOLVE, host);
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
curl_easy_perform(curl);
result = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);

View file

@ -53,10 +53,11 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_RESOLVER_START_FUNCTION, resolver_start_cb);
curl_easy_setopt(curl, CURLOPT_RESOLVER_START_DATA, curl);
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}

View file

@ -71,10 +71,11 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_RESOLVER_START_FUNCTION, start_cb);
curl_easy_setopt(curl, CURLOPT_RESOLVER_START_DATA, curl);
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}

View file

@ -53,6 +53,7 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
long size_of_file = 6789;
curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com");
@ -67,7 +68,8 @@ int main(void)
curl_easy_setopt(curl, CURLOPT_INFILESIZE, size_of_file);
/* Perform the request */
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -51,6 +51,7 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_off_t resume_position = 1234; /* get it somehow */
curl_off_t file_size = 9876; /* get it somehow as well */
@ -66,7 +67,8 @@ int main(void)
curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, file_size);
/* Perform the request */
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -55,6 +55,7 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
/* request to use a SOCKS5 proxy */
@ -64,7 +65,8 @@ int main(void)
curl_easy_setopt(curl, CURLOPT_SOCKS5_AUTH, CURLAUTH_BASIC);
/* Perform the request */
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -45,13 +45,15 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "sftp://example.com");
/* enable built-in compression */
curl_easy_setopt(curl, CURLOPT_SSH_COMPRESSION, 1L);
/* Perform the request */
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -56,12 +56,14 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
struct mine callback_data;
curl_easy_setopt(curl, CURLOPT_URL, "sftp://example.com/thisfile.txt");
curl_easy_setopt(curl, CURLOPT_SSH_HOSTKEYFUNCTION, hostkeycb);
curl_easy_setopt(curl, CURLOPT_SSH_HOSTKEYDATA, &callback_data);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -82,11 +82,13 @@ int main(void)
struct mine callback_data;
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "sftp://example.com/thisfile.txt");
curl_easy_setopt(curl, CURLOPT_SSH_HOSTKEYFUNCTION, hostkeycb);
curl_easy_setopt(curl, CURLOPT_SSH_HOSTKEYDATA, &callback_data);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -57,13 +57,15 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
struct mine callback_data;
curl_easy_setopt(curl, CURLOPT_URL, "sftp://example.com/thisfile.txt");
curl_easy_setopt(curl, CURLOPT_SSH_KEYFUNCTION, keycb);
curl_easy_setopt(curl, CURLOPT_SSH_KEYDATA, &callback_data);
curl_easy_setopt(curl, CURLOPT_SSH_KNOWNHOSTS, "/home/user/known_hosts");
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -134,13 +134,15 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
struct mine callback_data;
curl_easy_setopt(curl, CURLOPT_URL, "sftp://example.com/thisfile.txt");
curl_easy_setopt(curl, CURLOPT_SSH_KEYFUNCTION, keycb);
curl_easy_setopt(curl, CURLOPT_SSH_KEYDATA, &callback_data);
curl_easy_setopt(curl, CURLOPT_SSH_KNOWNHOSTS, "/home/user/known_hosts");
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -114,13 +114,15 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
/* ask libcurl to use TLS version 1.0 or later */
curl_easy_setopt(curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
/* Perform the request */
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -47,9 +47,11 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
curl_easy_setopt(curl, CURLOPT_SSL_FALSESTART, 1L);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -88,12 +88,14 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
/* Set the default value: strict name check please */
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2L);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -82,12 +82,14 @@ int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
/* Set the default value: strict certificate check please */
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
~~~

View file

@ -46,14 +46,20 @@ stderr
~~~c
int main(void)
{
CURL *curl = curl_easy_init();
CURL *curl;
FILE *filep = fopen("dump", "wb");
if(!filep)
return 1;
curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
curl_easy_setopt(curl, CURLOPT_STDERR, filep);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
fclose(filep);
}
~~~

Some files were not shown because too many files have changed in this diff Show more