open(F, "<$f");
open(O, ">$cfile");
print O "#include <curl/curl.h>\n";
- print O "extern struct CURLM *multi;\n";
- print O "extern struct CURL *easy;\n";
while(<F>) {
$iline++;
if(/^.SH EXAMPLE/) {
immediately with no action.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode res;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- res = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ res = curl_easy_perform(curl);
+ if(res)
+ printf("error: %s\\n", curl_easy_strerror(res));
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
the input handle may not be in use when cloned.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-CURL *nother;
-if(curl) {
- CURLcode res;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- nother = curl_easy_duphandle(curl);
- res = curl_easy_perform(nother);
- curl_easy_cleanup(nother);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ CURL *nother;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ nother = curl_easy_duphandle(curl);
+ res = curl_easy_perform(nother);
+ curl_easy_cleanup(nother);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
to the function is encoded correctly.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- char *output = curl_easy_escape(curl, "data to convert", 15);
- if(output) {
- printf("Encoded: %s\\n", output);
- curl_free(output);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ char *output = curl_easy_escape(curl, "data to convert", 15);
+ if(output) {
+ printf("Encoded: %s\\n", output);
+ curl_free(output);
+ }
+ curl_easy_cleanup(curl);
}
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
zero if no redirection took place.
.SH EXAMPLE
.nf
- curl = curl_easy_init();
+int main(void)
+{
+ CURL *curl = curl_easy_init();
if(curl) {
+ CURLcode res;
curl_easy_setopt(curl, CURLOPT_URL, "https://www.example.com/");
res = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);
}
+}
.fi
.SH AVAILABILITY
Added in 7.4.1
The header is an HTTP/2 or HTTP/3 pseudo header
.SH EXAMPLE
.nf
-struct curl_header *type;
-CURLHcode h =
- curl_easy_header(easy, "Content-Type", 0, CURLH_HEADER, -1, &type);
+int main(void)
+{
+ struct curl_header *type;
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLHcode h;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ curl_easy_perform(curl);
+ h = curl_easy_header(curl, "Content-Type", 0, CURLH_HEADER, -1, &type);
+ curl_easy_cleanup(curl);
+ }
+}
.fi
.SH AVAILABILITY
Added in 7.83.0. Officially supported since 7.84.0.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode res;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- res = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
want it to survive subsequent API calls or the life-time of the easy handle.
.SH EXAMPLE
.nf
-struct curl_header *prev = NULL;
-struct curl_header *h;
+int main(void)
+{
+ struct curl_header *prev = NULL;
+ struct curl_header *h;
-/* extract the normal headers from the first request */
-while((h = curl_easy_nextheader(easy, CURLH_HEADER, 0, prev))) {
- printf("%s: %s\\n", h->name, h->value);
- prev = h;
-}
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ curl_easy_perform(curl);
+
+ /* extract the normal headers from the first request */
+ while((h = curl_easy_nextheader(curl, CURLH_HEADER, 0, prev))) {
+ printf("%s: %s\\n", h->name, h->value);
+ prev = h;
+ }
-/* extract the normal headers + 1xx + trailers from the last request */
-unsigned int origin = CURLH_HEADER| CURLH_1XX | CURLH_TRAILER;
-while((h = curl_easy_nextheader(easy, origin, -1, prev))) {
- printf("%s: %s\\n", h->name, h->value);
- prev = h;
+ /* extract the normal headers + 1xx + trailers from the last request */
+ unsigned int origin = CURLH_HEADER| CURLH_1XX | CURLH_TRAILER;
+ while((h = curl_easy_nextheader(curl, origin, -1, prev))) {
+ printf("%s: %s\\n", h->name, h->value);
+ prev = h;
+ }
+ }
}
.fi
.SH AVAILABILITY
If libcurl has no option with the given id, this function returns NULL.
.SH EXAMPLE
.nf
-const struct curl_easyoption *opt = curl_easy_option_by_id(CURLOPT_URL);
-if(opt) {
- printf("This option wants type %x\\n", opt->type);
+int main(void)
+{
+ const struct curl_easyoption *opt = curl_easy_option_by_id(CURLOPT_URL);
+ if(opt) {
+ printf("This option wants type %x\\n", opt->type);
+ }
}
.fi
.SH AVAILABILITY
If libcurl has no option with the given name, this function returns NULL.
.SH EXAMPLE
.nf
-const struct curl_easyoption *opt = curl_easy_option_by_name("URL");
-if(opt) {
- printf("This option wants CURLoption %x\\n", (int)opt->id);
+int main(void)
+{
+ const struct curl_easyoption *opt = curl_easy_option_by_name("URL");
+ if(opt) {
+ printf("This option wants CURLoption %x\\n", (int)opt->id);
+ }
}
.fi
.SH AVAILABILITY
.fi
.SH EXAMPLE
.nf
-/* iterate over all available options */
-const struct curl_easyoption *opt;
-opt = curl_easy_option_next(NULL);
-while(opt) {
- printf("Name: %s\\n", opt->name);
- opt = curl_easy_option_next(opt);
+int main(void)
+{
+ /* iterate over all available options */
+ const struct curl_easyoption *opt;
+ opt = curl_easy_option_next(NULL);
+ while(opt) {
+ printf("Name: %s\\n", opt->name);
+ opt = curl_easy_option_next(opt);
+ }
}
.fi
.SH AVAILABILITY
first.
.SH EXAMPLE
.nf
-/* pause a transfer in both directions */
-curl_easy_pause(curl, CURL_READFUNC_PAUSE | CURL_WRITEFUNC_PAUSE);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ /* pause a transfer in both directions */
+ curl_easy_pause(curl, CURL_READFUNC_PAUSE | CURL_WRITEFUNC_PAUSE);
+
+ }
+}
.fi
.SH "MEMORY USE"
When pausing a download transfer by returning the magic return code from a
\fIcurl_easy_perform(3)\fP.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode res;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- res = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
read was for internal SSL processing, and no other data is available.
.SH EXAMPLE
.nf
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* Do not do the transfer - only connect to host */
- curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
- res = curl_easy_perform(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ /* Do not do the transfer - only connect to host */
+ curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
+ res = curl_easy_perform(curl);
- if(res == CURLE_OK) {
- /* Extract the socket from the curl handle - we need it for waiting. */
- res = curl_easy_getinfo(curl, CURLINFO_ACTIVESOCKET, &sockfd);
+ if(res == CURLE_OK) {
+ char buf[256];
+ size_t nread;
+ long sockfd;
- /* read data */
- res = curl_easy_recv(curl, buf, sizeof(buf), &nread);
- }
+ /* Extract the socket from the curl handle - we need it for waiting. */
+ res = curl_easy_getinfo(curl, CURLINFO_ACTIVESOCKET, &sockfd);
+
+ /* read data */
+ res = curl_easy_recv(curl, buf, sizeof(buf), &nread);
+ }
+ }
+}
.fi
.SH AVAILABILITY
Added in 7.18.2.
the alt-svc cache.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
-/* ... the handle is used and options are set ... */
-
-curl_easy_reset(curl);
+ /* ... the handle is used and options are set ... */
+ curl_easy_reset(curl);
+ }
+}
.fi
.SH AVAILABILITY
This function was added in libcurl 7.12.1
sent was for internal SSL processing, and no other data could be sent.
.SH EXAMPLE
.nf
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* Do not do the transfer - only connect to host */
- curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
- res = curl_easy_perform(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ /* Do not do the transfer - only connect to host */
+ curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
+ res = curl_easy_perform(curl);
- if(res == CURLE_OK) {
- /* Extract the socket from the curl handle - we need it for waiting. */
- res = curl_easy_getinfo(curl, CURLINFO_ACTIVESOCKET, &sockfd);
+ if(res == CURLE_OK) {
+ long sockfd;
+ size_t sent;
+ /* Extract the socket from the curl handle - we need it for waiting. */
+ res = curl_easy_getinfo(curl, CURLINFO_ACTIVESOCKET, &sockfd);
- /* send data */
- res = curl_easy_send(curl, "hello", 5, &sent);
- }
+ /* send data */
+ res = curl_easy_send(curl, "hello", 5, &sent);
+ }
+ }
+}
.fi
.SH AVAILABILITY
Added in 7.18.2.
TELNET options. See \fICURLOPT_TELNETOPTIONS(3)\fP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode res;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- res = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
specific error descriptions generated at runtime.
.SH EXAMPLE
.nf
- /* Perform the entire transfer */
- res = curl_easy_perform(curl);
- /* Check for errors */
- if(res != CURLE_OK)
- fprintf(stderr, "curl_easy_perform() failed: %s\\n",
- curl_easy_strerror(res));
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ /* set options */
+ /* Perform the entire transfer */
+ res = curl_easy_perform(curl);
+ /* Check for errors */
+ if(res != CURLE_OK)
+ fprintf(stderr, "curl_easy_perform() failed: %s\\n",
+ curl_easy_strerror(res));
+ }
+}
.fi
.SH AVAILABILITY
This function was added in libcurl 7.12.0
You must \fIcurl_free(3)\fP the returned string when you are done with it.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- int decodelen;
- char *decoded = curl_easy_unescape(curl, "%63%75%72%6c", 12, &decodelen);
- if(decoded) {
- /* do not assume printf() works on the decoded data! */
- printf("Decoded: ");
- /* ... */
- curl_free(decoded);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ int decodelen;
+ char *decoded = curl_easy_unescape(curl, "%63%75%72%6c", 12, &decodelen);
+ if(decoded) {
+ /* do not assume printf() works on the decoded data! */
+ printf("Decoded: ");
+ /* ... */
+ curl_free(decoded);
+ }
+ curl_easy_cleanup(curl);
}
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
\fICURLOPT_UPKEEP_INTERVAL_MS(3)\fP.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- /* Make a connection to an HTTP/2 server. */
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ /* Make a connection to an HTTP/2 server. */
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* Set the interval to 30000ms / 30s */
- curl_easy_setopt(curl, CURLOPT_UPKEEP_INTERVAL_MS, 30000L);
+ /* Set the interval to 30000ms / 30s */
+ curl_easy_setopt(curl, CURLOPT_UPKEEP_INTERVAL_MS, 30000L);
- curl_easy_perform(curl);
+ curl_easy_perform(curl);
- /* Perform more work here. */
+ /* Perform more work here. */
- /* While the connection is being held open, curl_easy_upkeep() can be
- called. If curl_easy_upkeep() is called and the time since the last
- upkeep exceeds the interval, then an HTTP/2 PING is sent. */
- curl_easy_upkeep(curl);
+ /* While the connection is being held open, curl_easy_upkeep() can be
+ called. If curl_easy_upkeep() is called and the time since the last
+ upkeep exceeds the interval, then an HTTP/2 PING is sent. */
+ curl_easy_upkeep(curl);
- /* Perform more work here. */
+ /* Perform more work here. */
- /* always cleanup */
- curl_easy_cleanup(curl);
+ /* always cleanup */
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
You must \fIcurl_free(3)\fP the returned string when you are done with it.
.SH EXAMPLE
.nf
-char *output = curl_escape("data to convert", 15);
-if(output) {
- printf("Encoded: %s\\n", output);
- curl_free(output);
+int main(void)
+{
+ char *output = curl_escape("data to convert", 15);
+ if(output) {
+ printf("Encoded: %s\\n", output);
+ curl_free(output);
+ }
}
.fi
.SH AVAILABILITY
See example below.
.SH EXAMPLE
.nf
- struct curl_httppost *post = NULL;
- struct curl_httppost *last = NULL;
- char namebuffer[] = "name buffer";
- long namelength = strlen(namebuffer);
- char buffer[] = "test buffer";
- char htmlbuffer[] = "<HTML>test buffer</HTML>";
- long htmlbufferlength = strlen(htmlbuffer);
- struct curl_forms forms[3];
- char file1[] = "my-face.jpg";
- char file2[] = "your-face.jpg";
- /* add null character into htmlbuffer, to demonstrate that
- transfers of buffers containing null characters actually work
- */
- htmlbuffer[8] = '\\0';
-
- /* Add simple name/content section */
- curl_formadd(&post, &last, CURLFORM_COPYNAME, "name",
- CURLFORM_COPYCONTENTS, "content", CURLFORM_END);
-
- /* Add simple name/content/contenttype section */
- curl_formadd(&post, &last, CURLFORM_COPYNAME, "htmlcode",
- CURLFORM_COPYCONTENTS, "<HTML></HTML>",
- CURLFORM_CONTENTTYPE, "text/html", CURLFORM_END);
-
- /* Add name/ptrcontent section */
- curl_formadd(&post, &last, CURLFORM_COPYNAME, "name_for_ptrcontent",
- CURLFORM_PTRCONTENTS, buffer, CURLFORM_END);
-
- /* Add ptrname/ptrcontent section */
- curl_formadd(&post, &last, CURLFORM_PTRNAME, namebuffer,
- CURLFORM_PTRCONTENTS, buffer, CURLFORM_NAMELENGTH,
- namelength, CURLFORM_END);
-
- /* Add name/ptrcontent/contenttype section */
- curl_formadd(&post, &last, CURLFORM_COPYNAME, "html_code_with_hole",
- CURLFORM_PTRCONTENTS, htmlbuffer,
- CURLFORM_CONTENTSLENGTH, htmlbufferlength,
- CURLFORM_CONTENTTYPE, "text/html", CURLFORM_END);
-
- /* Add simple file section */
- curl_formadd(&post, &last, CURLFORM_COPYNAME, "picture",
- CURLFORM_FILE, "my-face.jpg", CURLFORM_END);
-
- /* Add file/contenttype section */
- curl_formadd(&post, &last, CURLFORM_COPYNAME, "picture",
- CURLFORM_FILE, "my-face.jpg",
- CURLFORM_CONTENTTYPE, "image/jpeg", CURLFORM_END);
-
- /* Add two file section */
- curl_formadd(&post, &last, CURLFORM_COPYNAME, "pictures",
- CURLFORM_FILE, "my-face.jpg",
- CURLFORM_FILE, "your-face.jpg", CURLFORM_END);
-
- /* Add two file section using CURLFORM_ARRAY */
- forms[0].option = CURLFORM_FILE;
- forms[0].value = file1;
- forms[1].option = CURLFORM_FILE;
- forms[1].value = file2;
- forms[2].option = CURLFORM_END;
-
- /* Add a buffer to upload */
- curl_formadd(&post, &last,
- CURLFORM_COPYNAME, "name",
- CURLFORM_BUFFER, "data",
- CURLFORM_BUFFERPTR, record,
- CURLFORM_BUFFERLENGTH, record_length,
- CURLFORM_END);
-
- /* no option needed for the end marker */
- curl_formadd(&post, &last, CURLFORM_COPYNAME, "pictures",
- CURLFORM_ARRAY, forms, CURLFORM_END);
- /* Add the content of a file as a normal post text value */
- curl_formadd(&post, &last, CURLFORM_COPYNAME, "filecontent",
- CURLFORM_FILECONTENT, ".bashrc", CURLFORM_END);
- /* Set the form info */
- curl_easy_setopt(curl, CURLOPT_HTTPPOST, post);
+#include <string.h> /* for strlen */
+
+static const char record[]="data in a buffer";
+
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ struct curl_httppost *post = NULL;
+ struct curl_httppost *last = NULL;
+ char namebuffer[] = "name buffer";
+ long namelength = strlen(namebuffer);
+ char buffer[] = "test buffer";
+ char htmlbuffer[] = "<HTML>test buffer</HTML>";
+ long htmlbufferlength = strlen(htmlbuffer);
+ struct curl_forms forms[3];
+ char file1[] = "my-face.jpg";
+ char file2[] = "your-face.jpg";
+ /* add null character into htmlbuffer, to demonstrate that
+ transfers of buffers containing null characters actually work
+ */
+ htmlbuffer[8] = '\\0';
+
+ /* Add simple name/content section */
+ curl_formadd(&post, &last, CURLFORM_COPYNAME, "name",
+ CURLFORM_COPYCONTENTS, "content", CURLFORM_END);
+
+ /* Add simple name/content/contenttype section */
+ curl_formadd(&post, &last, CURLFORM_COPYNAME, "htmlcode",
+ CURLFORM_COPYCONTENTS, "<HTML></HTML>",
+ CURLFORM_CONTENTTYPE, "text/html", CURLFORM_END);
+
+ /* Add name/ptrcontent section */
+ curl_formadd(&post, &last, CURLFORM_COPYNAME, "name_for_ptrcontent",
+ CURLFORM_PTRCONTENTS, buffer, CURLFORM_END);
+
+ /* Add ptrname/ptrcontent section */
+ curl_formadd(&post, &last, CURLFORM_PTRNAME, namebuffer,
+ CURLFORM_PTRCONTENTS, buffer, CURLFORM_NAMELENGTH,
+ namelength, CURLFORM_END);
+
+ /* Add name/ptrcontent/contenttype section */
+ curl_formadd(&post, &last, CURLFORM_COPYNAME, "html_code_with_hole",
+ CURLFORM_PTRCONTENTS, htmlbuffer,
+ CURLFORM_CONTENTSLENGTH, htmlbufferlength,
+ CURLFORM_CONTENTTYPE, "text/html", CURLFORM_END);
+
+ /* Add simple file section */
+ curl_formadd(&post, &last, CURLFORM_COPYNAME, "picture",
+ CURLFORM_FILE, "my-face.jpg", CURLFORM_END);
+
+ /* Add file/contenttype section */
+ curl_formadd(&post, &last, CURLFORM_COPYNAME, "picture",
+ CURLFORM_FILE, "my-face.jpg",
+ CURLFORM_CONTENTTYPE, "image/jpeg", CURLFORM_END);
+
+ /* Add two file section */
+ curl_formadd(&post, &last, CURLFORM_COPYNAME, "pictures",
+ CURLFORM_FILE, "my-face.jpg",
+ CURLFORM_FILE, "your-face.jpg", CURLFORM_END);
+
+ /* Add two file section using CURLFORM_ARRAY */
+ forms[0].option = CURLFORM_FILE;
+ forms[0].value = file1;
+ forms[1].option = CURLFORM_FILE;
+ forms[1].value = file2;
+ forms[2].option = CURLFORM_END;
+
+ /* Add a buffer to upload */
+ curl_formadd(&post, &last,
+ CURLFORM_COPYNAME, "name",
+ CURLFORM_BUFFER, "data",
+ CURLFORM_BUFFERPTR, record,
+ CURLFORM_BUFFERLENGTH, sizeof(record),
+ CURLFORM_END);
+
+ /* no option needed for the end marker */
+ curl_formadd(&post, &last, CURLFORM_COPYNAME, "pictures",
+ CURLFORM_ARRAY, forms, CURLFORM_END);
+ /* Add the content of a file as a normal post text value */
+ curl_formadd(&post, &last, CURLFORM_COPYNAME, "filecontent",
+ CURLFORM_FILECONTENT, ".bashrc", CURLFORM_END);
+ /* Set the form info */
+ curl_easy_setopt(curl, CURLOPT_HTTPPOST, post);
+
+ curl_easy_perform(curl);
+
+ curl_easy_cleanup(curl);
+
+ curl_formfree(post);
+ }
+}
+.fi
.SH AVAILABILITY
Deprecated in 7.56.0. Before this release, field names were allowed to
contain zero-valued bytes. The pseudo-filename "-" to read stdin is
with no action.
.SH EXAMPLE
.nf
- /* Fill in a file upload field */
- curl_formadd(&formpost,
- &lastptr,
- CURLFORM_COPYNAME, "file",
- CURLFORM_FILE, "nice-image.jpg",
- CURLFORM_END);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ struct curl_httppost *formpost;
+ struct curl_httppost *lastptr;
- curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
+ /* Fill in a file upload field */
+ curl_formadd(&formpost,
+ &lastptr,
+ CURLFORM_COPYNAME, "file",
+ CURLFORM_FILE, "nice-image.jpg",
+ CURLFORM_END);
- curl_easy_perform(curl);
+ curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
- /* then cleanup the formpost chain */
- curl_formfree(formpost);
+ curl_easy_perform(curl);
+
+ /* then cleanup the formpost chain */
+ curl_formfree(formpost);
+ }
+}
.fi
.SH AVAILABILITY
Deprecated in 7.56.0.
callback to use!
.SH EXAMPLE
.nf
- size_t print_httppost_callback(void *arg, const char *buf, size_t len)
- {
- fwrite(buf, len, 1, stdout);
- (*(size_t *) arg) += len;
- return len;
- }
+size_t print_httppost_callback(void *arg, const char *buf, size_t len)
+{
+ fwrite(buf, len, 1, stdout);
+ (*(size_t *) arg) += len;
+ return len;
+}
- size_t print_httppost(struct curl_httppost *post)
- {
- size_t total_size = 0;
- if(curl_formget(post, &total_size, print_httppost_callback)) {
- return (size_t) -1;
- }
- return total_size;
- }
+size_t print_httppost(struct curl_httppost *post)
+{
+ size_t total_size = 0;
+ if(curl_formget(post, &total_size, print_httppost_callback)) {
+ return (size_t) -1;
+ }
+ return total_size;
+}
+.fi
.SH AVAILABILITY
This function was added in libcurl 7.15.5. The form API is deprecated in
libcurl 7.56.0.
with no action.
.SH EXAMPLE
.nf
+int main(void)
+{
char *width = curl_getenv("COLUMNS");
if(width) {
/* it was set! */
curl_free(width);
}
+}
.fi
.SH AVAILABILITY
Always
calendar date.
.SH EXAMPLE
.nf
- time_t t;
- t = curl_getdate("Sun, 06 Nov 1994 08:49:37 GMT", NULL);
- t = curl_getdate("Sunday, 06-Nov-94 08:49:37 GMT", NULL);
- t = curl_getdate("Sun Nov 6 08:49:37 1994", NULL);
- t = curl_getdate("06 Nov 1994 08:49:37 GMT", NULL);
- t = curl_getdate("06-Nov-94 08:49:37 GMT", NULL);
- t = curl_getdate("Nov 6 08:49:37 1994", NULL);
- t = curl_getdate("06 Nov 1994 08:49:37", NULL);
- t = curl_getdate("06-Nov-94 08:49:37", NULL);
- t = curl_getdate("1994 Nov 6 08:49:37", NULL);
- t = curl_getdate("GMT 08:49:37 06-Nov-94 Sunday", NULL);
- t = curl_getdate("94 6 Nov 08:49:37", NULL);
- t = curl_getdate("1994 Nov 6", NULL);
- t = curl_getdate("06-Nov-94", NULL);
- t = curl_getdate("Sun Nov 6 94", NULL);
- t = curl_getdate("1994.Nov.6", NULL);
- t = curl_getdate("Sun/Nov/6/94/GMT", NULL);
- t = curl_getdate("Sun, 06 Nov 1994 08:49:37 CET", NULL);
- t = curl_getdate("06 Nov 1994 08:49:37 EST", NULL);
- t = curl_getdate("Sun, 12 Sep 2004 15:05:58 -0700", NULL);
- t = curl_getdate("Sat, 11 Sep 2004 21:32:11 +0200", NULL);
- t = curl_getdate("20040912 15:05:58 -0700", NULL);
- t = curl_getdate("20040911 +0200", NULL);
+int main(void)
+{
+ time_t t;
+ t = curl_getdate("Sun, 06 Nov 1994 08:49:37 GMT", NULL);
+ t = curl_getdate("Sunday, 06-Nov-94 08:49:37 GMT", NULL);
+ t = curl_getdate("Sun Nov 6 08:49:37 1994", NULL);
+ t = curl_getdate("06 Nov 1994 08:49:37 GMT", NULL);
+ t = curl_getdate("06-Nov-94 08:49:37 GMT", NULL);
+ t = curl_getdate("Nov 6 08:49:37 1994", NULL);
+ t = curl_getdate("06 Nov 1994 08:49:37", NULL);
+ t = curl_getdate("06-Nov-94 08:49:37", NULL);
+ t = curl_getdate("1994 Nov 6 08:49:37", NULL);
+ t = curl_getdate("GMT 08:49:37 06-Nov-94 Sunday", NULL);
+ t = curl_getdate("94 6 Nov 08:49:37", NULL);
+ t = curl_getdate("1994 Nov 6", NULL);
+ t = curl_getdate("06-Nov-94", NULL);
+ t = curl_getdate("Sun Nov 6 94", NULL);
+ t = curl_getdate("1994.Nov.6", NULL);
+ t = curl_getdate("Sun/Nov/6/94/GMT", NULL);
+ t = curl_getdate("Sun, 06 Nov 1994 08:49:37 CET", NULL);
+ t = curl_getdate("06 Nov 1994 08:49:37 EST", NULL);
+ t = curl_getdate("Sun, 12 Sep 2004 15:05:58 -0700", NULL);
+ t = curl_getdate("Sat, 11 Sep 2004 21:32:11 +0200", NULL);
+ t = curl_getdate("20040912 15:05:58 -0700", NULL);
+ t = curl_getdate("20040911 +0200", NULL);
+}
.fi
.SH STANDARDS
This parser handles date formats specified in RFC 822 (including the update in
You must \fIcurl_free(3)\fP the returned string when you are done with it.
.SH EXAMPLE
.nf
+int main(void)
+{
char *width = curl_getenv("COLUMNS");
if(width) {
/* it was set! */
curl_free(width);
}
+}
.fi
.SH AVAILABILITY
Always
dynamically. This behavior may be addressed in the future.
.SH EXAMPLE
.nf
- curl_global_init(CURL_GLOBAL_DEFAULT);
+int main(void)
+{
+ curl_global_init(CURL_GLOBAL_DEFAULT);
- /* use libcurl, then before exiting... */
+ /* use libcurl, then before exiting... */
- curl_global_cleanup();
+ curl_global_cleanup();
+}
.fi
.SH AVAILABILITY
Added in 7.8
elapses. (Added in 7.30.0)
.SH EXAMPLE
.nf
- curl_global_init(CURL_GLOBAL_DEFAULT);
+int main(void)
+{
+ curl_global_init(CURL_GLOBAL_DEFAULT);
- /* use libcurl, then before exiting... */
+ /* use libcurl, then before exiting... */
- curl_global_cleanup();
+ curl_global_cleanup();
+}
.fi
.SH AVAILABILITY
Added in 7.8
screw things up for libcurl. Take care!
.SH EXAMPLE
.nf
- curl_global_init_mem(CURL_GLOBAL_DEFAULT, curl_malloc_cb,
- curl_free_cb, curl_realloc_cb,
- curl_strdup_cb, curl_calloc_cb);
+extern void *malloc_cb(size_t);
+extern void free_cb(void *);
+extern void *realloc_cb(void *, size_t);
+extern char *strdup_cb(const char *);
+extern void *calloc_cb(size_t, size_t);
+
+int main(void)
+{
+ curl_global_init_mem(CURL_GLOBAL_DEFAULT, malloc_cb,
+ free_cb, realloc_cb,
+ strdup_cb, calloc_cb);
+}
.fi
.SH AVAILABILITY
Added in 7.12.0
.fi
.SH EXAMPLE
.nf
+int main(void)
+{
+ int i;
/* choose a specific backend */
curl_global_sslset(CURLSSLBACKEND_WOLFSSL, NULL, NULL);
for(i = 0; list[i]; i++)
printf("SSL backend #%d: '%s' (ID: %d)\\n",
i, list[i]->name, list[i]->id);
+}
.fi
.SH AVAILABILITY
This function was added in libcurl 7.56.0. Before this version, there was no
.SH EXAMPLE
.nf
- /* log details of HTTP/2 and SSL handling */
- curl_global_trace("http/2,ssl");
+int main(void)
+{
+ /* log details of HTTP/2 and SSL handling */
+ curl_global_trace("http/2,ssl");
- /* log all details, except SSL handling */
- curl_global_trace("all,-ssl");
+ /* log all details, except SSL handling */
+ curl_global_trace("all,-ssl");
+}
.fi
Below is a trace sample where "http/2" was configured. The trace output
appended.
.SH EXAMPLE
.nf
- curl_mime *mime;
- curl_mimepart *part;
+int main(void)
+{
+ curl_mime *mime;
+ curl_mimepart *part;
- /* create a mime handle */
- mime = curl_mime_init(easy);
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ /* create a mime handle */
+ mime = curl_mime_init(curl);
- /* add a part */
- part = curl_mime_addpart(mime);
+ /* add a part */
+ part = curl_mime_addpart(mime);
- /* continue and set name + data to the part */
- curl_mime_data(part, "This is the field data", CURL_ZERO_TERMINATED);
- curl_mime_name(part, "data");
+ /* continue and set name + data to the part */
+ curl_mime_data(part, "This is the field data", CURL_ZERO_TERMINATED);
+ curl_mime_name(part, "data");
+ }
+}
.fi
.SH AVAILABILITY
As long as at least one of HTTP, SMTP or IMAP is enabled. Added in 7.56.0.
\fIcurl_mime_data_cb(3)\fP in such a case.
.SH EXAMPLE
.nf
- curl_mime *mime;
- curl_mimepart *part;
+int main(void)
+{
+ curl_mime *mime;
+ curl_mimepart *part;
- /* create a mime handle */
- mime = curl_mime_init(easy);
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ /* create a mime handle */
+ mime = curl_mime_init(curl);
- /* add a part */
- part = curl_mime_addpart(mime);
+ /* add a part */
+ part = curl_mime_addpart(mime);
- /* add data to the part */
- curl_mime_data(part, "raw contents to send", CURL_ZERO_TERMINATED);
+ /* add data to the part */
+ curl_mime_data(part, "raw contents to send", CURL_ZERO_TERMINATED);
+ }
+}
.fi
.SH AVAILABILITY
As long as at least one of HTTP, SMTP or IMAP is enabled. Added in 7.56.0.
source to avoid data duplication. In this case, original data must be retained
until after the transfer terminates.
.nf
-
+#include <string.h> /* for memcpy */
char hugedata[512000];
struct ctl {
return CURL_SEEKFUNC_OK;
}
- CURL *easy = curl_easy_init();
- curl_mime *mime = curl_mime_init(easy);
- curl_mimepart *part = curl_mime_addpart(mime);
- struct ctl hugectl;
-
- hugectl.buffer = hugedata;
- hugectl.size = sizeof hugedata;
- hugectl.position = 0;
- curl_mime_data_cb(part, hugectl.size, read_callback, seek_callback, NULL,
- &hugectl);
-
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_mime *mime = curl_mime_init(curl);
+ curl_mimepart *part = curl_mime_addpart(mime);
+ struct ctl hugectl;
+
+ hugectl.buffer = hugedata;
+ hugectl.size = sizeof(hugedata);
+ hugectl.position = 0;
+ curl_mime_data_cb(part, hugectl.size, read_callback, seek_callback, NULL,
+ &hugectl);
+ }
+}
+.fi
.SH AVAILABILITY
As long as at least one of HTTP, SMTP or IMAP is enabled. Added in 7.56.0.
.SH RETURN VALUE
discouraged.
.SH EXAMPLE
.nf
- curl_mime *mime;
- curl_mimepart *part;
+int main(void)
+{
+ curl_mime *mime;
+ curl_mimepart *part;
- /* create a mime handle */
- mime = curl_mime_init(easy);
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ /* create a mime handle */
+ mime = curl_mime_init(curl);
- /* add a part */
- part = curl_mime_addpart(mime);
+ /* add a part */
+ part = curl_mime_addpart(mime);
- /* send a file */
- curl_mime_filedata(part, "image.png");
+ /* send a file */
+ curl_mime_filedata(part, "image.png");
- /* encode file data in base64 for transfer */
- curl_mime_encoder(part, "base64");
+ /* encode file data in base64 for transfer */
+ curl_mime_encoder(part, "base64");
+ }
+}
.fi
.SH AVAILABILITY
As long as at least one of HTTP, SMTP or IMAP is enabled. Added in 7.56.0.
last call is retained.
.SH EXAMPLE
.nf
- curl_mime *mime;
- curl_mimepart *part;
+int main(void)
+{
+ curl_mime *mime;
+ curl_mimepart *part;
- /* create a mime handle */
- mime = curl_mime_init(easy);
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ /* create a mime handle */
+ mime = curl_mime_init(curl);
- /* add a part */
- part = curl_mime_addpart(mime);
+ /* add a part */
+ part = curl_mime_addpart(mime);
- /* send data from this file */
- curl_mime_filedata(part, "image.png");
+ /* send data from this file */
+ curl_mime_filedata(part, "image.png");
- /* set name */
- curl_mime_name(part, "data");
+ /* set name */
+ curl_mime_name(part, "data");
+ }
+}
.fi
.SH AVAILABILITY
As long as at least one of HTTP, SMTP or IMAP is enabled. Added in 7.56.0.
name multiple times is valid: only the value set by the last call is retained.
.SH EXAMPLE
.nf
- curl_mime *mime;
- curl_mimepart *part;
- /* create a mime handle */
- mime = curl_mime_init(easy);
+static char imagebuf[]="imagedata";
- /* add a part */
- part = curl_mime_addpart(mime);
+int main(void)
+{
+ curl_mime *mime;
+ curl_mimepart *part;
- /* send image data from memory */
- curl_mime_data(part, imagebuf, imagebuf_len);
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ /* create a mime handle */
+ mime = curl_mime_init(curl);
- /* set a file name to make it look like a file upload */
- curl_mime_filename(part, "image.png");
+ /* add a part */
+ part = curl_mime_addpart(mime);
- /* set name */
- curl_mime_name(part, "data");
+ /* send image data from memory */
+ curl_mime_data(part, imagebuf, sizeof(imagebuf));
+
+ /* set a file name to make it look like a file upload */
+ curl_mime_filename(part, "image.png");
+
+ /* set name */
+ curl_mime_name(part, "data");
+ }
+}
.fi
.SH AVAILABILITY
As long as at least one of HTTP, SMTP or IMAP is enabled. Added in 7.56.0.
with no action.
.SH EXAMPLE
.nf
- /* Build the mime message. */
- mime = curl_mime_init(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ /* Build the mime message. */
+ curl_mime *mime = curl_mime_init(curl);
- /* ... */
+ /* send off the transfer */
- /* Free multipart message. */
- curl_mime_free(mime);
+ /* Free multipart message. */
+ curl_mime_free(mime);
+ }
+}
.fi
.SH AVAILABILITY
As long as at least one of HTTP, SMTP or IMAP is enabled. Added in 7.56.0.
set by the last call is retained.
.SH EXAMPLE
.nf
- struct curl_slist *headers = NULL;
+int main(void)
+{
+ struct curl_slist *headers = NULL;
+ CURL *easy = curl_easy_init();
+ curl_mime *mime;
+ curl_mimepart *part;
- headers = curl_slist_append(headers, "Custom-Header: mooo");
+ headers = curl_slist_append(headers, "Custom-Header: mooo");
- /* use these headers, please take ownership */
- curl_mime_headers(part, headers, TRUE);
+ mime = curl_mime_init(easy);
+ part = curl_mime_addpart(mime);
- /* pass on this data */
- curl_mime_data(part, "12345679", CURL_ZERO_TERMINATED);
+ /* use these headers in the part, takes ownership */
+ curl_mime_headers(part, headers, 1);
- /* set name */
- curl_mime_name(part, "numbers");
+ /* pass on this data */
+ curl_mime_data(part, "12345679", CURL_ZERO_TERMINATED);
+
+ /* set name */
+ curl_mime_name(part, "numbers");
+
+ /* Post and send it. */
+ curl_easy_setopt(easy, CURLOPT_MIMEPOST, mime);
+ curl_easy_setopt(easy, CURLOPT_URL, "https://example.com");
+ curl_easy_perform(easy);
+}
.fi
.SH AVAILABILITY
As long as at least one of HTTP, SMTP or IMAP is enabled. Added in 7.56.0.
send a multi-part email with SMTP or upload such an email to an IMAP server.
.SH EXAMPLE
.nf
- CURL *easy = curl_easy_init();
- curl_mime *mime;
- curl_mimepart *part;
+int main(void)
+{
+ CURL *easy = curl_easy_init();
+ curl_mime *mime;
+ curl_mimepart *part;
- /* Build an HTTP form with a single field named "data", */
- mime = curl_mime_init(easy);
- part = curl_mime_addpart(mime);
- curl_mime_data(part, "This is the field data", CURL_ZERO_TERMINATED);
- curl_mime_name(part, "data");
+ /* Build an HTTP form with a single field named "data", */
+ mime = curl_mime_init(easy);
+ part = curl_mime_addpart(mime);
+ curl_mime_data(part, "This is the field data", CURL_ZERO_TERMINATED);
+ curl_mime_name(part, "data");
- /* Post and send it. */
- curl_easy_setopt(easy, CURLOPT_MIMEPOST, mime);
- curl_easy_setopt(easy, CURLOPT_URL, "https://example.com");
- curl_easy_perform(easy);
+ /* Post and send it. */
+ curl_easy_setopt(easy, CURLOPT_MIMEPOST, mime);
+ curl_easy_setopt(easy, CURLOPT_URL, "https://example.com");
+ curl_easy_perform(easy);
- /* Clean-up. */
- curl_easy_cleanup(easy);
- curl_mime_free(mime);
+ /* Clean-up. */
+ curl_easy_cleanup(easy);
+ curl_mime_free(mime);
+}
+.fi
.SH AVAILABILITY
As long as at least one of HTTP, SMTP or IMAP is enabled. Added in 7.56.0.
.SH RETURN VALUE
reset the name of a part by setting \fIname\fP to NULL.
.SH EXAMPLE
.nf
- curl_mime *mime;
- curl_mimepart *part;
+int main(void)
+{
+ curl_mime *mime;
+ curl_mimepart *part;
- /* create a mime handle */
- mime = curl_mime_init(easy);
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ /* create a mime handle */
+ mime = curl_mime_init(curl);
- /* add a part */
- part = curl_mime_addpart(mime);
+ /* add a part */
+ part = curl_mime_addpart(mime);
- /* give the part a name */
- curl_mime_name(part, "shoe_size");
+ /* give the part a name */
+ curl_mime_name(part, "shoe_size");
+ }
+}
.fi
.SH AVAILABILITY
As long as at least one of HTTP, SMTP or IMAP is enabled. Added in 7.56.0.
setting \fIsubparts\fP to NULL.
.SH EXAMPLE
.nf
- /* The inline part is an alternative proposing the html and the text
- versions of the email. */
- alt = curl_mime_init(curl);
- /* HTML message. */
- part = curl_mime_addpart(alt);
- curl_mime_data(part, inline_html, CURL_ZERO_TERMINATED);
- curl_mime_type(part, "text/html");
+static char *inline_html = "<title>example</title>";
+static char *inline_text = "once upon the time";
- /* Text message. */
- part = curl_mime_addpart(alt);
- curl_mime_data(part, inline_text, CURL_ZERO_TERMINATED);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ struct curl_slist *slist;
- /* Create the inline part. */
- part = curl_mime_addpart(mime);
- curl_mime_subparts(part, alt);
- curl_mime_type(part, "multipart/alternative");
- slist = curl_slist_append(NULL, "Content-Disposition: inline");
- curl_mime_headers(part, slist, 1);
+ /* The inline part is an alternative proposing the html and the text
+ versions of the email. */
+ curl_mime *alt = curl_mime_init(curl);
+ curl_mimepart *part;
+
+ /* HTML message. */
+ part = curl_mime_addpart(alt);
+ curl_mime_data(part, inline_html, CURL_ZERO_TERMINATED);
+ curl_mime_type(part, "text/html");
+
+ /* Text message. */
+ part = curl_mime_addpart(alt);
+ curl_mime_data(part, inline_text, CURL_ZERO_TERMINATED);
+
+ /* Create the inline part. */
+ part = curl_mime_addpart(alt);
+ curl_mime_subparts(part, alt);
+ curl_mime_type(part, "multipart/alternative");
+ slist = curl_slist_append(NULL, "Content-Disposition: inline");
+ curl_mime_headers(part, slist, 1);
+ }
+}
.fi
.SH AVAILABILITY
As long as at least one of HTTP, SMTP or IMAP is enabled. Added in 7.56.0.
- text/plain in other cases.
.SH EXAMPLE
.nf
- curl_mime *mime;
- curl_mimepart *part;
+int main(void)
+{
+ curl_mime *mime;
+ curl_mimepart *part;
- /* create a mime handle */
- mime = curl_mime_init(easy);
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ /* create a mime handle */
+ mime = curl_mime_init(curl);
- /* add a part */
- part = curl_mime_addpart(mime);
+ /* add a part */
+ part = curl_mime_addpart(mime);
- /* get data from this file */
- curl_mime_filedata(part, "image.png");
+ /* get data from this file */
+ curl_mime_filedata(part, "image.png");
- /* content-type for this part */
- curl_mime_type(part, "image/png");
+ /* content-type for this part */
+ curl_mime_type(part, "image/png");
- /* set name */
- curl_mime_name(part, "image");
+ /* set name */
+ curl_mime_name(part, "image");
+}
+}
.fi
.SH AVAILABILITY
As long as at least one of HTTP, SMTP or IMAP is enabled. Added in 7.56.0.
A '%' is written. No argument is converted.
.SH EXAMPLE
.nf
+const char *name = "John";
+
+int main(void)
+{
curl_mprintf("My name is %s\\n", name);
- curl_mprintf("Pi is almost %f\\n", 25/8);
+ curl_mprintf("Pi is almost %f\\n", (double)25.0/8);
+}
.fi
.SH AVAILABILITY
These functions might be removed from the public libcurl API in the future. Do
3 - \fIcurl_multi_cleanup(3)\fP
.SH EXAMPLE
.nf
+int main(void)
+{
/* init a multi stack */
- multi_handle = curl_multi_init();
+ CURLM *multi = curl_multi_init();
+
+ /* create two easy handles */
+ CURL *http_handle = curl_easy_init();
+ CURL *http_handle2 = curl_easy_init();
/* add individual transfers */
- curl_multi_add_handle(multi_handle, http_handle);
- curl_multi_add_handle(multi_handle, http_handle2);
+ curl_multi_add_handle(multi, http_handle);
+ curl_multi_add_handle(multi, http_handle2);
+}
.fi
.SH AVAILABILITY
Added in 7.9.6
It is acceptable to call this function from your multi callback functions.
.SH EXAMPLE
.nf
- /* make our struct pointer associated with socket fd */
- mc = curl_multi_assign(multi_handle, fd, ourstructp);
+int main(void)
+{
+ CURLM *multi = curl_multi_init();
+ void *ourstructp; /* pointer to our data */
+ curl_socket_t fd; /* file descriptor to associate our data with */
+
+ /* make our struct pointer associated with socket fd */
+ CURLMcode mc = curl_multi_assign(multi, fd, ourstructp);
+ if(mc)
+ printf("error: %s\\n", curl_multi_strerror(mc));
+}
.fi
.SH AVAILABILITY
Added in 7.15.5
CURLM_BAD_HANDLE immediately with no other action.
.SH EXAMPLE
.nf
- /* when the multi transfer is done ... */
+int main(void)
+{
+ CURLM *multi = curl_multi_init();
- /* remove all easy handles, then: */
- curl_multi_cleanup(multi_handle);
+ /* when the multi transfer is done ... */
+
+ /* remove all easy handles, then: */
+ curl_multi_cleanup(multi);
+}
.fi
.SH AVAILABILITY
Added in 7.9.6
wait for...
.SH EXAMPLE
.nf
- /* get file descriptors from the transfers */
- mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
+int main(void)
+{
+ fd_set fdread;
+ fd_set fdwrite;
+ fd_set fdexcep;
+ int maxfd;
+ int rc;
+ CURLMcode mc;
+ struct timeval timeout = {1, 0};
- if(mc != CURLM_OK) {
- fprintf(stderr, "curl_multi_fdset() failed, code %d.\\n", mc);
- break;
- }
+ CURLM *multi = curl_multi_init();
- /* wait for activity on one of the sockets */
- rc = select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
+ do {
+
+ /* call curl_multi_perform() */
+
+ /* get file descriptors from the transfers */
+ mc = curl_multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);
+
+ if(mc != CURLM_OK) {
+ fprintf(stderr, "curl_multi_fdset() failed, code %d.\\n", mc);
+ break;
+ }
+
+ /* wait for activity on one of the sockets */
+ rc = select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
+
+ } while(!mc);
+}
.fi
.SH AVAILABILITY
Added in 7.9.6
The returned array must be freed with a call to \fIcurl_free(3)\fP after use.
.SH EXAMPLE
.nf
+int main(void)
+{
/* init a multi stack */
- multi_handle = curl_multi_init();
+ CURLM *multi = curl_multi_init();
+ CURL *curl = curl_easy_init();
- /* add a transfer */
- curl_multi_add_handle(multi_handle, http_handle);
+ if(curl) {
+ /* add the transfer */
+ curl_multi_add_handle(multi, curl);
- /* extract all added handles */
- CURL **list = curl_multi_get_handles(multi_handle);
+ /* extract all added handles */
+ CURL **list = curl_multi_get_handles(multi);
- if(list) {
- /* remove all added handles */
- for(i = 0; list[i]; i++) {
- curl_multi_remove_handle(multi_handle, list[i]);
+ if(list) {
+ int i;
+ /* remove all added handles */
+ for(i = 0; list[i]; i++) {
+ curl_multi_remove_handle(multi, list[i]);
+ }
+ curl_free(list);
}
- curl_free(list);
}
+}
.fi
.SH AVAILABILITY
Added in 8.4.0
At this point, there are no other \fBmsg\fP types defined.
.SH EXAMPLE
.nf
-struct CURLMsg *m;
+int main(void)
+{
+ CURLM *multi = curl_multi_init();
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ struct CURLMsg *m;
-/* call curl_multi_perform or curl_multi_socket_action first, then loop
- through and check if there are any transfers that have completed */
+ /* call curl_multi_perform or curl_multi_socket_action first, then loop
+ through and check if there are any transfers that have completed */
-do {
- int msgq = 0;
- m = curl_multi_info_read(multi_handle, &msgq);
- if(m && (m->msg == CURLMSG_DONE)) {
- CURL *e = m->easy_handle;
- transfers--;
- curl_multi_remove_handle(multi_handle, e);
- curl_easy_cleanup(e);
+ do {
+ int msgq = 0;
+ m = curl_multi_info_read(multi, &msgq);
+ if(m && (m->msg == CURLMSG_DONE)) {
+ CURL *e = m->easy_handle;
+ /* m->data.result holds the error code for the transfer */
+ curl_multi_remove_handle(multi, e);
+ curl_easy_cleanup(e);
+ }
+ } while(m);
}
-} while(m);
+}
.fi
.SH AVAILABILITY
Added in 7.9.6
\fIcurl_multi_cleanup(3)\fP when the operation is complete.
.SH EXAMPLE
.nf
-/* init a multi stack */
-multi_handle = curl_multi_init();
+int main(void)
+{
+ /* init a multi stack */
+ CURLM *multi = curl_multi_init();
+ CURL *curl = curl_easy_init();
+ CURL *curl2 = curl_easy_init();
-/* add individual transfers */
-curl_multi_add_handle(multi_handle, http_handle);
-curl_multi_add_handle(multi_handle, http_handle2);
+ /* add individual transfers */
+ curl_multi_add_handle(multi, curl);
+ curl_multi_add_handle(multi, curl2);
+}
.fi
.SH AVAILABILITY
Added in 7.9.6
removing all the handles and adding new ones.
.SH EXAMPLE
.nf
-int still_running;
-do {
- CURLMcode mc = curl_multi_perform(multi_handle, &still_running);
+int main(void)
+{
+ int still_running;
+ CURL *multi = curl_multi_init();
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_multi_add_handle(multi, curl);
+ do {
+ CURLMcode mc = curl_multi_perform(multi, &still_running);
- if(!mc && still_running)
- /* wait for activity, timeout or "nothing" */
- mc = curl_multi_poll(multi_handle, NULL, 0, 1000, NULL);
+ if(!mc && still_running)
+ /* wait for activity, timeout or "nothing" */
+ mc = curl_multi_poll(multi, NULL, 0, 1000, NULL);
- if(mc) {
- fprintf(stderr, "curl_multi_poll() failed, code %d.\\n", (int)mc);
- break;
- }
+ if(mc) {
+ fprintf(stderr, "curl_multi_poll() failed, code %d.\\n", (int)mc);
+ break;
+ }
-/* if there are still transfers, loop! */
-} while(still_running);
+ /* if there are still transfers, loop! */
+ } while(still_running);
+ }
+}
.fi
.SH AVAILABILITY
Added in 7.9.6
events such as the socket being clear to write without blocking.
.SH EXAMPLE
.nf
-CURL *easy_handle;
-CURLM *multi_handle;
+int main(void)
+{
+ CURL *easy_handle;
+ CURLM *multi_handle;
+ int still_running = 0;
-/* add the individual easy handle */
-curl_multi_add_handle(multi_handle, easy_handle);
+ /* add the individual easy handle */
+ curl_multi_add_handle(multi_handle, easy_handle);
-do {
- CURLMcode mc;
- int numfds;
+ do {
+ CURLMcode mc;
+ int numfds;
- mc = curl_multi_perform(multi_handle, &still_running);
+ mc = curl_multi_perform(multi_handle, &still_running);
- if(mc == CURLM_OK) {
- /* wait for activity or timeout */
- mc = curl_multi_poll(multi_handle, NULL, 0, 1000, &numfds);
- }
+ if(mc == CURLM_OK) {
+ /* wait for activity or timeout */
+ mc = curl_multi_poll(multi_handle, NULL, 0, 1000, &numfds);
+ }
- if(mc != CURLM_OK) {
- fprintf(stderr, "curl_multi failed, code %d.\\n", mc);
- break;
- }
+ if(mc != CURLM_OK) {
+ fprintf(stderr, "curl_multi failed, code %d.\\n", mc);
+ break;
+ }
-} while(still_running);
+ } while(still_running);
-curl_multi_remove_handle(multi_handle, easy_handle);
+ curl_multi_remove_handle(multi_handle, easy_handle);
+}
.fi
.SH AVAILABILITY
Added in 7.66.0.
handle.
.SH EXAMPLE
.nf
-/* when an easy handle has completed, remove it */
-msg = curl_multi_info_read(multi_handle, &queued);
-if(msg) {
- if(msg->msg == CURLMSG_DONE) {
- /* a transfer ended */
- fprintf(stderr, "Transfer completed\\n");
- curl_multi_remove_handle(multi_handle, msg->easy_handle);
+int main(void)
+{
+ CURLM *multi = curl_multi_init();
+ int queued = 0;
+
+ /* when an easy handle has completed, remove it */
+ CURLMsg *msg = curl_multi_info_read(multi, &queued);
+ if(msg) {
+ if(msg->msg == CURLMSG_DONE) {
+ /* a transfer ended */
+ fprintf(stderr, "Transfer completed\\n");
+ curl_multi_remove_handle(multi, msg->easy_handle);
+ }
}
}
.fi
.IP CURLMOPT_MAX_CONCURRENT_STREAMS
See \fICURLMOPT_MAX_CONCURRENT_STREAMS(3)\fP
.SH EXAMPLE
-.fi
- /* Limit the amount of simultaneous connections curl should allow: */
- curl_multi_setopt(handle, CURLMOPT_MAXCONNECTS, (long)MAX_PARALLEL);
.nf
+
+#define MAX_PARALLEL 45
+
+int main(void)
+{
+ CURLM *multi;
+ /* Limit the amount of simultaneous connections curl should allow: */
+ curl_multi_setopt(multi, CURLMOPT_MAXCONNECTS, (long)MAX_PARALLEL);
+}
+.fi
.SH AVAILABILITY
Added in 7.15.4
.SH RETURN VALUE
should not be any reason to use this function.
.SH EXAMPLE
.nf
-/* the event-library gets told when there activity on the socket 'fd',
- which we translate to a call to curl_multi_socket_action() */
-int running;
-rc = curl_multi_socket(multi_handle, fd, &running);
+int main(void)
+{
+ /* the event-library gets told when there activity on the socket 'fd',
+ which we translate to a call to curl_multi_socket_action() */
+ int running;
+ int rc;
+ int fd;
+ CURLM *multi;
+ rc = curl_multi_socket(multi, fd, &running);
+}
.fi
.SH AVAILABILITY
This function was added in libcurl 7.15.4, and is deemed stable since
call \fIcurl_multi_socket_action(3)\fP with \fICURL_SOCKET_TIMEOUT\fP.
.SH EXAMPLE
.nf
-/* the event-library gets told when there activity on the socket 'fd',
- which we translate to a call to curl_multi_socket_action() */
-int running;
-rc = curl_multi_socket_action(multi_handle, fd, EVENT,
- &running);
+int main(void)
+{
+ /* the event-library gets told when there activity on the socket 'fd',
+ which we translate to a call to curl_multi_socket_action() */
+ int running;
+ CURLM *multi; /* the stack we work with */
+ int fd; /* the descriptor that had action */
+ int bitmask; /* what activity that happened */
+ CURLMcode mc = curl_multi_socket_action(multi, fd, bitmask, &running);
+ if(mc)
+ printf("error: %s\\n", curl_multi_strerror(mc));
+}
.fi
.SH AVAILABILITY
This function was added in libcurl 7.15.4, and is deemed stable since 7.16.0.
passed in the argument \fIerrornum\fP.
.SH EXAMPLE
.nf
-int still_running;
+int main(void)
+{
+ int still_running;
+ CURLM *multi = curl_multi_init();
-CURLMcode mc = curl_multi_perform(multi_handle, &still_running);
-if(mc)
- printf("error: %s\\n", curl_multi_strerror(mc));
+ CURLMcode mc = curl_multi_perform(multi, &still_running);
+ if(mc)
+ printf("error: %s\\n", curl_multi_strerror(mc));
+}
.fi
.SH AVAILABILITY
This function was added in libcurl 7.12.0
few seconds perhaps) before you call \fIcurl_multi_perform(3)\fP again.
.SH EXAMPLE
.nf
-struct timeval timeout;
-long timeo;
+int main(void)
+{
+ struct timeval timeout;
+ long timeo;
+ fd_set fdread;
+ fd_set fdwrite;
+ fd_set fdexcep;
+ int maxfd;
+ CURLM *multi = curl_multi_init();
-curl_multi_timeout(multi_handle, &timeo);
-if(timeo < 0)
- /* no set timeout, use a default */
- timeo = 980;
+ curl_multi_timeout(multi, &timeo);
+ if(timeo < 0)
+ /* no set timeout, use a default */
+ timeo = 980;
-timeout.tv_sec = timeo / 1000;
-timeout.tv_usec = (timeo % 1000) * 1000;
+ timeout.tv_sec = timeo / 1000;
+ timeout.tv_usec = (timeo % 1000) * 1000;
-/* wait for activities no longer than the set timeout */
-select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
+ /* wait for activities no longer than the set timeout */
+ select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
+}
.fi
.SH TYPICAL USAGE
Call \fIcurl_multi_timeout(3)\fP, then wait for action on the sockets. Figure
write events such as the socket being clear to write without blocking.
.SH EXAMPLE
.nf
-CURL *easy_handle;
-CURLM *multi_handle;
+int main(void)
+{
+ CURL *easy;
+ CURLM *multi = curl_multi_init();
+ int still_running;
-/* add the individual easy handle */
-curl_multi_add_handle(multi_handle, easy_handle);
+ /* add the individual easy handle */
+ curl_multi_add_handle(multi, easy);
-do {
- CURLMcode mc;
- int numfds;
+ do {
+ CURLMcode mc;
+ int numfds;
- mc = curl_multi_perform(multi_handle, &still_running);
+ mc = curl_multi_perform(multi, &still_running);
- if(mc == CURLM_OK ) {
- /* wait for activity, timeout or "nothing" */
- mc = curl_multi_wait(multi_handle, NULL, 0, 1000, &numfds);
- }
-
- if(mc != CURLM_OK) {
- fprintf(stderr, "curl_multi failed, code %d.\\n", mc);
- break;
- }
-
- /* 'numfds' being zero means either a timeout or no file descriptors to
- wait for. Try timeout on first occurrence, then assume no file
- descriptors and no file descriptors to wait for means wait for 100
- milliseconds. */
+ if(mc == CURLM_OK) {
+ /* wait for activity, timeout or "nothing" */
+ mc = curl_multi_wait(multi, NULL, 0, 1000, &numfds);
+ }
- if(!numfds) {
- repeats++; /* count number of repeated zero numfds */
- if(repeats > 1) {
- WAITMS(100); /* sleep 100 milliseconds */
+ if(mc != CURLM_OK) {
+ fprintf(stderr, "curl_multi failed, code %d.\\n", mc);
+ break;
}
- }
- else
- repeats = 0;
-} while(still_running);
+ } while(still_running);
-curl_multi_remove_handle(multi_handle, easy_handle);
+ curl_multi_remove_handle(multi, easy);
+}
.fi
.SH AVAILABILITY
This function was added in libcurl 7.28.0.
This function has no effect on \fIcurl_multi_wait(3)\fP calls.
.SH EXAMPLE
.nf
-CURL *easy_handle;
-CURLM *multi_handle;
+extern int time_to_die(void);
+extern int set_something_to_signal_thread_1_to_exit(void);
+extern int decide_to_stop_thread1();
-/* add the individual easy handle */
-curl_multi_add_handle(multi_handle, easy_handle);
+int main(void)
+{
+ CURL *easy;
+ CURLM *multi;
+ int still_running;
-/* this is thread 1 */
-do {
- CURLMcode mc;
- int numfds;
+ /* add the individual easy handle */
+ curl_multi_add_handle(multi, easy);
- mc = curl_multi_perform(multi_handle, &still_running);
+ /* this is thread 1 */
+ do {
+ CURLMcode mc;
+ int numfds;
- if(mc == CURLM_OK) {
- /* wait for activity, timeout or wakeup */
- mc = curl_multi_poll(multi_handle, NULL, 0, 10000, &numfds);
- }
+ mc = curl_multi_perform(multi, &still_running);
- if(time_to_die())
- exit(1);
+ if(mc == CURLM_OK) {
+ /* wait for activity, timeout or wakeup */
+ mc = curl_multi_poll(multi, NULL, 0, 10000, &numfds);
+ }
-} while(still_running);
+ if(time_to_die())
+ return 1;
-curl_multi_remove_handle(multi_handle, easy_handle);
+ } while(still_running);
-/* this is thread 2 */
+ curl_multi_remove_handle(multi, easy);
-if(something makes us decide to stop thread 1) {
+ /* this is thread 2 */
- set_something_to_signal_thread_1_to_exit();
+ if(decide_to_stop_thread1()) {
- curl_multi_wakeup(multi_handle);
-}
+ set_something_to_signal_thread_1_to_exit();
+ curl_multi_wakeup(multi);
+ }
+}
.fi
.SH AVAILABILITY
Added in 7.68.0
.SH EXAMPLE
.nf
-int curl_push_callback(CURL *parent,
- CURL *easy,
- size_t num_headers,
- struct curl_pushheaders *headers,
- void *clientp)
+#include <string.h> /* for strncmp */
+
+static int push_cb(CURL *parent,
+ CURL *easy,
+ size_t num_headers,
+ struct curl_pushheaders *headers,
+ void *clientp)
{
char *headp;
int *transfers = (int *)clientp;
return CURL_PUSH_DENY;
}
-curl_multi_setopt(multi, CURLMOPT_PUSHFUNCTION, curl_push_callback);
-curl_multi_setopt(multi, CURLMOPT_PUSHDATA, &counter);
+int main(void)
+{
+ int counter;
+ CURLM *multi = curl_multi_init();
+ curl_multi_setopt(multi, CURLMOPT_PUSHFUNCTION, push_cb);
+ curl_multi_setopt(multi, CURLMOPT_PUSHDATA, &counter);
+}
.fi
.SH AVAILABILITY
Added in 7.44.0
.SH EXAMPLE
.nf
/* output all the incoming push request headers */
-int curl_push_callback(CURL *parent,
- CURL *easy,
- size_t num_headers,
- struct curl_pushheaders *headers,
- void *clientp)
+static int push_cb(CURL *parent,
+ CURL *easy,
+ size_t num_headers,
+ struct curl_pushheaders *headers,
+ void *clientp)
{
- sizt_t i = 0;
+ int i = 0;
char *field;
do {
field = curl_pushheader_bynum(headers, i);
return CURL_PUSH_OK; /* permission granted */
}
-curl_multi_setopt(multi, CURLMOPT_PUSHFUNCTION, curl_push_callback);
+int main(void)
+{
+ CURLM *multi = curl_multi_init();
+ curl_multi_setopt(multi, CURLMOPT_PUSHFUNCTION, push_cb);
+}
.fi
.SH AVAILABILITY
Added in 7.44.0
immediately with no action.
.SH EXAMPLE
.nf
+int main(void)
+{
CURLSHcode sh;
- share = curl_share_init();
+ CURLSH *share = curl_share_init();
sh = curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT);
/* use the share, then ... */
curl_share_cleanup(share);
+}
.fi
.SH AVAILABILITY
Added in 7.10
specific curl handle use the data in this share.
.SH EXAMPLE
.nf
+int main(void)
+{
CURLSHcode sh;
- share = curl_share_init();
+ CURLSH *share = curl_share_init();
sh = curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT);
if(sh)
printf("Error: %s\\n", curl_share_strerror(sh));
+}
.fi
.SH AVAILABILITY
Added in 7.10
See \fICURLSHOPT_USERDATA(3)\fP.
.SH EXAMPLE
.nf
+int main(void)
+{
CURLSHcode sh;
- share = curl_share_init();
+ CURLSH *share = curl_share_init();
sh = curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT);
if(sh)
printf("Error: %s\\n", curl_share_strerror(sh));
+}
.fi
.SH AVAILABILITY
Added in 7.10
\fICURLSHcode\fP error code passed in the argument \fIerrornum\fP.
.SH EXAMPLE
.nf
+int main(void)
+{
CURLSHcode sh;
- share = curl_share_init();
+ CURLSH *share = curl_share_init();
sh = curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT);
if(sh)
printf("Error: %s\\n", curl_share_strerror(sh));
+}
.fi
.SH AVAILABILITY
This function was added in libcurl 7.12.0
\fIcurl_slist_free_all(3)\fP.
.SH EXAMPLE
.nf
-CURL *handle;
-struct curl_slist *slist=NULL;
-struct curl_slist *temp=NULL;
+int main(void)
+{
+ CURL *handle;
+ struct curl_slist *slist = NULL;
+ struct curl_slist *temp = NULL;
-slist = curl_slist_append(slist, "pragma:");
+ slist = curl_slist_append(slist, "pragma:");
-if (slist == NULL)
- return -1;
+ if(!slist)
+ return -1;
-temp = curl_slist_append(slist, "Accept:")
+ temp = curl_slist_append(slist, "Accept:");
-if (temp == NULL) {
- curl_slist_free_all(slist);
- return -1;
-}
+ if(!temp) {
+ curl_slist_free_all(slist);
+ return -1;
+ }
-slist = temp;
+ slist = temp;
-curl_easy_setopt(handle, CURLOPT_HTTPHEADER, slist);
+ curl_easy_setopt(handle, CURLOPT_HTTPHEADER, slist);
-curl_easy_perform(handle);
+ curl_easy_perform(handle);
-curl_slist_free_all(slist); /* free the list again */
+ curl_slist_free_all(slist); /* free the list again */
+}
.fi
.SH AVAILABILITY
Always
with no action.
.SH EXAMPLE
.nf
-CURL *handle;
-struct curl_slist *slist=NULL;
+int main(void)
+{
+ CURL *handle;
+ struct curl_slist *slist = NULL;
-slist = curl_slist_append(slist, "X-libcurl: coolness");
+ slist = curl_slist_append(slist, "X-libcurl: coolness");
-if (slist == NULL)
- return -1;
+ if(!slist)
+ return -1;
-curl_easy_setopt(handle, CURLOPT_HTTPHEADER, slist);
+ curl_easy_setopt(handle, CURLOPT_HTTPHEADER, slist);
-curl_easy_perform(handle);
+ curl_easy_perform(handle);
-curl_slist_free_all(slist); /* free the list again */
+ curl_slist_free_all(slist); /* free the list again */
+}
.fi
.SH AVAILABILITY
Always
insensitive string comparison functions. These two work on all platforms.
.SH EXAMPLE
.nf
-if(curl_strequal(name, input))
- printf("Name and input matches\\n");
-if(curl_strnequal(name, input, 5))
- printf("Name and input matches in the 5 first bytes\\n");
+int main(int argc, char **argv)
+{
+ const char *name = "compare";
+ if(curl_strequal(name, argv[1]))
+ printf("Name and input matches\\n");
+ if(curl_strnequal(name, argv[1], 5))
+ printf("Name and input matches in the 5 first bytes\\n");
+}
.fi
.SH AVAILABILITY
Always
You must \fIcurl_free(3)\fP the returned string when you are done with it.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- int decodelen;
- char *decoded = curl_unescape("%63%75%72%6c", 12, &decodelen);
- if(decoded) {
- /* do not assume printf() works on the decoded data! */
- printf("Decoded: ");
- /* ... */
- curl_free(decoded);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ char *decoded = curl_unescape("%63%75%72%6c", 12);
+ if(decoded) {
+ /* do not assume printf() works on the decoded data! */
+ printf("Decoded: ");
+ /* ... */
+ curl_free(decoded);
+ }
}
}
.fi
function.
.SH EXAMPLE
.nf
+int main(void)
+{
CURLUcode rc;
CURLU *url = curl_url();
rc = curl_url_set(url, CURLUPART_URL, "https://example.com", 0);
}
curl_url_cleanup(url);
}
+}
.fi
.SH AVAILABILITY
Added in 7.62.0
immediately with no action.
.SH EXAMPLE
.nf
+int main(void)
+{
CURLU *url = curl_url();
curl_url_set(url, CURLUPART_URL, "https://example.com", 0);
curl_url_cleanup(url);
+}
.fi
.SH AVAILABILITY
Added in 7.62.0
needs to be freed with \fIcurl_url_cleanup(3)\fP.
.SH EXAMPLE
.nf
+int main(void)
+{
CURLUcode rc;
CURLU *url = curl_url();
CURLU *url2;
curl_url_cleanup(url2);
}
curl_url_cleanup(url);
+}
.fi
.SH AVAILABILITY
Added in 7.62.0
delimiter only. It is not part of the fragment contents.
.SH EXAMPLE
.nf
+int main(void)
+{
CURLUcode rc;
CURLU *url = curl_url();
rc = curl_url_set(url, CURLUPART_URL, "https://example.com", 0);
}
curl_url_cleanup(url);
}
+}
.fi
.SH AVAILABILITY
Added in 7.62.0. CURLUPART_ZONEID was added in 7.65.0.
such URLs.
.SH EXAMPLE
.nf
+int main(void)
+{
CURLUcode rc;
CURLU *url = curl_url();
rc = curl_url_set(url, CURLUPART_URL, "https://example.com", 0);
if(!rc) {
- char *scheme;
/* change it to an FTP URL */
rc = curl_url_set(url, CURLUPART_SCHEME, "ftp", 0);
}
curl_url_cleanup(url);
+}
.fi
.SH AVAILABILITY
Added in 7.62.0. CURLUPART_ZONEID was added in 7.65.0.
the argument \fIerrornum\fP.
.SH EXAMPLE
.nf
+int main(void)
+{
CURLUcode rc;
CURLU *url = curl_url();
rc = curl_url_set(url, CURLUPART_URL, "https://example.com", 0);
if(rc)
printf("URL error: %s\\n", curl_url_strerror(rc));
curl_url_cleanup(url);
+}
.fi
-
.SH AVAILABILITY
Added in 7.80.0
.SH RETURN VALUE
We recommend using \fIcurl_version_info(3)\fP instead!
.SH EXAMPLE
.nf
-printf("libcurl version %s\\n", curl_version());
+int main(void)
+{
+ printf("libcurl version %s\\n", curl_version());
+}
.fi
.SH AVAILABILITY
entry.
.SH EXAMPLE
.nf
-curl_version_info_data *ver = curl_version_info(CURLVERSION_NOW);
-printf("libcurl version %u.%u.%u\\n",
- (ver->version_num >> 16) & 0xff,
- (ver->version_num >> 8) & 0xff,
- ver->version_num & 0xff);
+int main(void)
+{
+ curl_version_info_data *ver = curl_version_info(CURLVERSION_NOW);
+ printf("libcurl version %u.%u.%u\\n",
+ (ver->version_num >> 16) & 0xff,
+ (ver->version_num >> 8) & 0xff,
+ ver->version_num & 0xff);
+}
.fi
.SH AVAILABILITY
Added in 7.10
struct customdata *c = (struct customdata *)p;
const struct curl_ws_frame *m = curl_ws_meta(c->easy);
- /* m->flags tells us about the traffic */
+ printf("flags: %x\\n", m->flags);
}
+int main(void)
{
- struct customdata custom;
- custom.easy = easy;
- custom.ptr = NULL;
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writecb);
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, &custom);
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ struct customdata custom;
+ custom.easy = curl;
+ custom.ptr = NULL;
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writecb);
+ curl_easy_setopt(curl, CURLOPT_WRITEDATA, &custom);
+
+ curl_easy_perform(curl);
+
+ }
}
.fi
.SH AVAILABILITY
\fIcurl_ws_meta(3)\fP for details on that struct.
.SH EXAMPLE
.nf
+int main(void)
+{
size_t rlen;
const struct curl_ws_frame *meta;
char buffer[256];
- CURLcode result = curl_ws_recv(curl, buffer, sizeof(buffer), &rlen, &meta);
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res = curl_ws_recv(curl, buffer, sizeof(buffer), &rlen, &meta);
+ if(res)
+ printf("error: %s\\n", curl_easy_strerror(res));
+ }
+}
.fi
.SH AVAILABILITY
Added in 7.86.0.
calls.
.SH EXAMPLE
.nf
-int ping(CURL *curl, const char *send_payload)
+#include <string.h> /* for strlen */
+
+const char *send_payload = "magic";
+
+int main(void)
{
size_t sent;
- CURLcode result =
- curl_ws_send(curl, send_payload, strlen(send_payload), &sent, 0,
- CURLWS_PING);
- return (int)result;
+ CURLcode res;
+ CURL *curl = curl_easy_init();
+ curl_easy_setopt(curl, CURLOPT_URL, "wss://example.com/");
+ curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 2L);
+ curl_easy_perform(curl);
+ res = curl_ws_send(curl, send_payload, strlen(send_payload), &sent, 0,
+ CURLWS_PING);
+ curl_easy_cleanup(curl);
+ return (int)res;
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_socket_t sockfd;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_socket_t sockfd;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* Do not do the transfer - only connect to host */
- curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
- res = curl_easy_perform(curl);
+ /* Do not do the transfer - only connect to host */
+ curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
+ res = curl_easy_perform(curl);
- /* Extract the socket from the curl handle */
- res = curl_easy_getinfo(curl, CURLINFO_ACTIVESOCKET, &sockfd);
+ /* Extract the socket from the curl handle */
+ res = curl_easy_getinfo(curl, CURLINFO_ACTIVESOCKET, &sockfd);
- if(res != CURLE_OK) {
- printf("Error: %s\\n", curl_easy_strerror(res));
- return 1;
+ if(res != CURLE_OK) {
+ printf("Error: %s\\n", curl_easy_strerror(res));
+ return 1;
+ }
}
}
.fi
All
.SH EXAMPLE
.nf
-curl = curl_easy_init();
-if(curl) {
- double connect;
- curl_easy_setopt(curl, CURLOPT_URL, url);
- res = curl_easy_perform(curl);
- if(CURLE_OK == res) {
- res = curl_easy_getinfo(curl, CURLINFO_APPCONNECT_TIME, &connect);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ double connect;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ res = curl_easy_perform(curl);
if(CURLE_OK == res) {
- printf("Time: %.1f", connect);
+ res = curl_easy_getinfo(curl, CURLINFO_APPCONNECT_TIME, &connect);
+ if(CURLE_OK == res) {
+ printf("Time: %.1f", connect);
+ }
}
+ /* always cleanup */
+ curl_easy_cleanup(curl);
}
- /* always cleanup */
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-curl = curl_easy_init();
-if(curl) {
- curl_off_t connect;
- curl_easy_setopt(curl, CURLOPT_URL, url);
- res = curl_easy_perform(curl);
- if(CURLE_OK == res) {
- res = curl_easy_getinfo(curl, CURLINFO_APPCONNECT_TIME_T, &connect);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_off_t connect;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ res = curl_easy_perform(curl);
if(CURLE_OK == res) {
- printf("Time: %" CURL_FORMAT_CURL_OFF_T ".%06ld", connect / 1000000,
- (long)(connect % 1000000));
+ res = curl_easy_getinfo(curl, CURLINFO_APPCONNECT_TIME_T, &connect);
+ if(CURLE_OK == res) {
+ printf("Time: %" CURL_FORMAT_CURL_OFF_T ".%06ld", connect / 1000000,
+ (long)(connect % 1000000));
+ }
}
+ /* always cleanup */
+ curl_easy_cleanup(curl);
}
- /* always cleanup */
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode res;
- char *cainfo = NULL;
- curl_easy_getinfo(curl, CURLINFO_CAINFO, &cainfo);
- if(cainfo)
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ char *cainfo = NULL;
+ curl_easy_getinfo(curl, CURLINFO_CAINFO, &cainfo);
+ if(cainfo) {
printf("default ca info path: %s\\n", cainfo);
+ }
+ curl_easy_cleanup(curl);
}
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode res;
- char *capath = NULL;
- curl_easy_getinfo(curl, CURLINFO_CAPATH, &capath);
- if(capath)
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ char *capath = NULL;
+ curl_easy_getinfo(curl, CURLINFO_CAPATH, &capath);
+ if(capath) {
printf("default ca path: %s\\n", capath);
+ }
+ curl_easy_cleanup(curl);
}
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
All TLS-based
.SH EXAMPLE
.nf
-curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://www.example.com/");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://www.example.com/");
- /* connect to any HTTPS site, trusted or not */
- curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
- curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
+ /* connect to any HTTPS site, trusted or not */
+ curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
+ curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
- curl_easy_setopt(curl, CURLOPT_CERTINFO, 1L);
+ curl_easy_setopt(curl, CURLOPT_CERTINFO, 1L);
- res = curl_easy_perform(curl);
+ res = curl_easy_perform(curl);
- if (!res) {
- struct curl_certinfo *ci;
- res = curl_easy_getinfo(curl, CURLINFO_CERTINFO, &ci);
+ if(!res) {
+ int i;
+ struct curl_certinfo *ci;
+ res = curl_easy_getinfo(curl, CURLINFO_CERTINFO, &ci);
- if (!res) {
- printf("%d certs!\\n", ci->num_of_certs);
+ if(!res) {
+ printf("%d certs!\\n", ci->num_of_certs);
- for(i = 0; i < ci->num_of_certs; i++) {
- struct curl_slist *slist;
+ for(i = 0; i < ci->num_of_certs; i++) {
+ struct curl_slist *slist;
- for(slist = ci->certinfo[i]; slist; slist = slist->next)
- printf("%s\\n", slist->data);
+ for(slist = ci->certinfo[i]; slist; slist = slist->next)
+ printf("%s\\n", slist->data);
+ }
}
}
+ curl_easy_cleanup(curl);
}
- curl_easy_cleanup(curl);
}
.fi
HTTP and some
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
- /* January 1, 2020 is 1577833200 */
- curl_easy_setopt(curl, CURLOPT_TIMEVALUE, 1577833200L);
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* If-Modified-Since the above time stamp */
- curl_easy_setopt(curl, CURLOPT_TIMECONDITION,
- (long)CURL_TIMECOND_IFMODSINCE);
+ /* January 1, 2020 is 1577833200 */
+ curl_easy_setopt(curl, CURLOPT_TIMEVALUE, 1577833200L);
- /* Perform the request */
- res = curl_easy_perform(curl);
+ /* If-Modified-Since the above time stamp */
+ curl_easy_setopt(curl, CURLOPT_TIMECONDITION,
+ (long)CURL_TIMECOND_IFMODSINCE);
+
+ /* Perform the request */
+ res = curl_easy_perform(curl);
- if(!res) {
- /* check the time condition */
- long unmet;
- res = curl_easy_getinfo(curl, CURLINFO_CONDITION_UNMET, &unmet);
if(!res) {
- printf("The time condition was %sfulfilled\\n", unmet?"NOT":"");
+ /* check the time condition */
+ long unmet;
+ res = curl_easy_getinfo(curl, CURLINFO_CONDITION_UNMET, &unmet);
+ if(!res) {
+ printf("The time condition was %sfulfilled\\n", unmet?"NOT":"");
+ }
}
}
}
All
.SH EXAMPLE
.nf
-curl = curl_easy_init();
-if(curl) {
- double connect;
- curl_easy_setopt(curl, CURLOPT_URL, url);
- res = curl_easy_perform(curl);
- if(CURLE_OK == res) {
- res = curl_easy_getinfo(curl, CURLINFO_CONNECT_TIME, &connect);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ double connect;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ res = curl_easy_perform(curl);
if(CURLE_OK == res) {
- printf("Time: %.1f", connect);
+ res = curl_easy_getinfo(curl, CURLINFO_CONNECT_TIME, &connect);
+ if(CURLE_OK == res) {
+ printf("Time: %.1f", connect);
+ }
}
+ /* always cleanup */
+ curl_easy_cleanup(curl);
}
- /* always cleanup */
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-curl = curl_easy_init();
-if(curl) {
- curl_off_t connect;
- curl_easy_setopt(curl, CURLOPT_URL, url);
- res = curl_easy_perform(curl);
- if(CURLE_OK == res) {
- res = curl_easy_getinfo(curl, CURLINFO_CONNECT_TIME_T, &connect);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_off_t connect;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ res = curl_easy_perform(curl);
if(CURLE_OK == res) {
- printf("Time: %" CURL_FORMAT_CURL_OFF_T ".%06ld", connect / 1000000,
- (long)(connect % 1000000));
+ res = curl_easy_getinfo(curl, CURLINFO_CONNECT_TIME_T, &connect);
+ if(CURLE_OK == res) {
+ printf("Time: %" CURL_FORMAT_CURL_OFF_T ".%06ld", connect / 1000000,
+ (long)(connect % 1000000));
+ }
}
+ /* always cleanup */
+ curl_easy_cleanup(curl);
}
- /* always cleanup */
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
- /* Perform the request */
- res = curl_easy_perform(curl);
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+
+ /* Perform the request */
+ res = curl_easy_perform(curl);
- if(!res) {
- curl_off_t conn_id;
- res = curl_easy_getinfo(curl, CURLINFO_CONN_ID, &conn_id);
if(!res) {
- printf("Connection used: %" CURL_FORMAT_CURL_OFF_T "\\n", conn_id);
+ curl_off_t conn_id;
+ res = curl_easy_getinfo(curl, CURLINFO_CONN_ID, &conn_id);
+ if(!res) {
+ printf("Connection used: %" CURL_FORMAT_CURL_OFF_T "\\n", conn_id);
+ }
}
}
}
HTTP(S)
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* Perform the request */
- res = curl_easy_perform(curl);
+ /* Perform the request */
+ res = curl_easy_perform(curl);
- if(!res) {
- /* check the size */
- double cl;
- res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &cl);
if(!res) {
- printf("Size: %.0f\\n", cl);
+ /* check the size */
+ double cl;
+ res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &cl);
+ if(!res) {
+ printf("Size: %.0f\\n", cl);
+ }
}
}
}
HTTP(S)
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* Perform the request */
- res = curl_easy_perform(curl);
+ /* Perform the request */
+ res = curl_easy_perform(curl);
- if(!res) {
- /* check the size */
- curl_off_t cl;
- res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD_T, &cl);
if(!res) {
- printf("Download size: %" CURL_FORMAT_CURL_OFF_T "\\n", cl);
+ /* check the size */
+ curl_off_t cl;
+ res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD_T, &cl);
+ if(!res) {
+ printf("Download size: %" CURL_FORMAT_CURL_OFF_T "\\n", cl);
+ }
}
}
}
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* Perform the upload */
- res = curl_easy_perform(curl);
+ /* Perform the upload */
+ res = curl_easy_perform(curl);
- if(!res) {
- /* check the size */
- double cl;
- res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_UPLOAD, &cl);
if(!res) {
- printf("Size: %.0f\\n", cl);
+ /* check the size */
+ double cl;
+ res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_UPLOAD, &cl);
+ if(!res) {
+ printf("Size: %.0f\\n", cl);
+ }
}
}
}
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* Perform the upload */
- res = curl_easy_perform(curl);
+ /* Perform the upload */
+ res = curl_easy_perform(curl);
- if(!res) {
- /* check the size */
- curl_off_t cl;
- res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_UPLOAD_T, &cl);
if(!res) {
- printf("Upload size: %" CURL_FORMAT_CURL_OFF_T "\\n", cl);
+ /* check the size */
+ curl_off_t cl;
+ res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_UPLOAD_T, &cl);
+ if(!res) {
+ printf("Upload size: %" CURL_FORMAT_CURL_OFF_T "\\n", cl);
+ }
}
}
}
HTTP(S)
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- res = curl_easy_perform(curl);
+ res = curl_easy_perform(curl);
- if(!res) {
- /* extract the content-type */
- char *ct = NULL;
- res = curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &ct);
- if(!res && ct) {
- printf("Content-Type: %s\\n", ct);
+ if(!res) {
+ /* extract the content-type */
+ char *ct = NULL;
+ res = curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &ct);
+ if(!res && ct) {
+ printf("Content-Type: %s\\n", ct);
+ }
}
+ curl_easy_cleanup(curl);
}
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
HTTP(S)
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* enable the cookie engine */
- curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "");
+ /* enable the cookie engine */
+ curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "");
- res = curl_easy_perform(curl);
+ res = curl_easy_perform(curl);
- if(!res) {
- /* extract all known cookies */
- struct curl_slist *cookies = NULL;
- res = curl_easy_getinfo(curl, CURLINFO_COOKIELIST, &cookies);
- if(!res && cookies) {
- /* a linked list of cookies in cookie file format */
- struct curl_slist *each = cookies;
- while(each) {
- printf("%s\\n", each->data);
- each = each->next;
+ if(!res) {
+ /* extract all known cookies */
+ struct curl_slist *cookies = NULL;
+ res = curl_easy_getinfo(curl, CURLINFO_COOKIELIST, &cookies);
+ if(!res && cookies) {
+ /* a linked list of cookies in cookie file format */
+ struct curl_slist *each = cookies;
+ while(each) {
+ printf("%s\\n", each->data);
+ each = each->next;
+ }
+ /* we must free these cookies when we are done */
+ curl_slist_free_all(cookies);
}
- /* we must free these cookies when we are done */
- curl_slist_free_all(cookies);
}
+ curl_easy_cleanup(curl);
}
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
HTTP(S)
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode res;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "data");
- curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
- res = curl_easy_perform(curl);
- if(res == CURLE_OK) {
- char *method = NULL;
- curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_METHOD, &method);
- if(method)
- printf("Redirected to method: %s\\n", method);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "data");
+ curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
+ res = curl_easy_perform(curl);
+ if(res == CURLE_OK) {
+ char *method = NULL;
+ curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_METHOD, &method);
+ if(method)
+ printf("Redirected to method: %s\\n", method);
+ }
+ curl_easy_cleanup(curl);
}
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
HTTP(S)
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode res;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
- res = curl_easy_perform(curl);
- if(res == CURLE_OK) {
- char *url = NULL;
- curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url);
- if(url)
- printf("Redirect to: %s\\n", url);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
+ res = curl_easy_perform(curl);
+ if(res == CURLE_OK) {
+ char *url = NULL;
+ curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url);
+ if(url)
+ printf("Redirect to: %s\\n", url);
+ }
+ curl_easy_cleanup(curl);
}
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
HTTP(S), FTP(S), SFTP
.SH EXAMPLE
.nf
-curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, url);
- /* Ask for filetime */
- curl_easy_setopt(curl, CURLOPT_FILETIME, 1L);
- res = curl_easy_perform(curl);
- if(CURLE_OK == res) {
- res = curl_easy_getinfo(curl, CURLINFO_FILETIME, &filetime);
- if((CURLE_OK == res) && (filetime >= 0)) {
- time_t file_time = (time_t)filetime;
- printf("filetime %s: %s", filename, ctime(&file_time));
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ /* Ask for filetime */
+ curl_easy_setopt(curl, CURLOPT_FILETIME, 1L);
+ res = curl_easy_perform(curl);
+ if(CURLE_OK == res) {
+ long filetime = 0;
+ res = curl_easy_getinfo(curl, CURLINFO_FILETIME, &filetime);
+ if((CURLE_OK == res) && (filetime >= 0)) {
+ time_t file_time = (time_t)filetime;
+ printf("filetime: %s", ctime(&file_time));
+ }
}
+ /* always cleanup */
+ curl_easy_cleanup(curl);
}
- /* always cleanup */
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
HTTP(S), FTP(S), SFTP
.SH EXAMPLE
.nf
-curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, url);
- /* Ask for filetime */
- curl_easy_setopt(curl, CURLOPT_FILETIME, 1L);
- res = curl_easy_perform(curl);
- if(CURLE_OK == res) {
- curl_off_t filetime;
- res = curl_easy_getinfo(curl, CURLINFO_FILETIME_T, &filetime);
- if((CURLE_OK == res) && (filetime >= 0)) {
- time_t file_time = (time_t)filetime;
- printf("filetime %s: %s", filename, ctime(&file_time));
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ /* Ask for filetime */
+ curl_easy_setopt(curl, CURLOPT_FILETIME, 1L);
+ res = curl_easy_perform(curl);
+ if(CURLE_OK == res) {
+ curl_off_t filetime;
+ res = curl_easy_getinfo(curl, CURLINFO_FILETIME_T, &filetime);
+ if((CURLE_OK == res) && (filetime >= 0)) {
+ time_t file_time = (time_t)filetime;
+ printf("filetime: %s", ctime(&file_time));
+ }
}
+ /* always cleanup */
+ curl_easy_cleanup(curl);
}
- /* always cleanup */
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
FTP(S) and SFTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com");
- res = curl_easy_perform(curl);
+ res = curl_easy_perform(curl);
- if(!res) {
- /* extract the entry path */
- char *ep = NULL;
- res = curl_easy_getinfo(curl, CURLINFO_FTP_ENTRY_PATH, &ep);
- if(!res && ep) {
- printf("Entry path was: %s\\n", ep);
+ if(!res) {
+ /* extract the entry path */
+ char *ep = NULL;
+ res = curl_easy_getinfo(curl, CURLINFO_FTP_ENTRY_PATH, &ep);
+ if(!res && ep) {
+ printf("Entry path was: %s\\n", ep);
+ }
}
+ curl_easy_cleanup(curl);
}
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode res;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- res = curl_easy_perform(curl);
- if(res == CURLE_OK) {
- long size;
- res = curl_easy_getinfo(curl, CURLINFO_HEADER_SIZE, &size);
- if(!res)
- printf("Header size: %ld bytes\\n", size);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ res = curl_easy_perform(curl);
+ if(res == CURLE_OK) {
+ long size;
+ res = curl_easy_getinfo(curl, CURLINFO_HEADER_SIZE, &size);
+ if(!res)
+ printf("Header size: %ld bytes\\n", size);
+ }
+ curl_easy_cleanup(curl);
}
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
HTTP(S)
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- res = curl_easy_perform(curl);
+ res = curl_easy_perform(curl);
- if(!res) {
- /* extract the available authentication types */
- long auth;
- res = curl_easy_getinfo(curl, CURLINFO_HTTPAUTH_AVAIL, &auth);
if(!res) {
- if(!auth)
- printf("No auth available, perhaps no 401?\\n");
- else {
- printf("%s%s%s%s\\n",
- auth & CURLAUTH_BASIC ? "Basic ":"",
- auth & CURLAUTH_DIGEST ? "Digest ":"",
- auth & CURLAUTH_NEGOTIATE ? "Negotiate ":"",
- auth % CURLAUTH_NTLM ? "NTLM ":"");
+ /* extract the available authentication types */
+ long auth;
+ res = curl_easy_getinfo(curl, CURLINFO_HTTPAUTH_AVAIL, &auth);
+ if(!res) {
+ if(!auth)
+ printf("No auth available, perhaps no 401?\\n");
+ else {
+ printf("%s%s%s%s\\n",
+ auth & CURLAUTH_BASIC ? "Basic ":"",
+ auth & CURLAUTH_DIGEST ? "Digest ":"",
+ auth & CURLAUTH_NEGOTIATE ? "Negotiate ":"",
+ auth % CURLAUTH_NTLM ? "NTLM ":"");
+ }
}
}
+ curl_easy_cleanup(curl);
}
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
HTTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode res;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* typically CONNECT is used to do HTTPS over HTTP proxies */
- curl_easy_setopt(curl, CURLOPT_PROXY, "http://127.0.0.1");
- res = curl_easy_perform(curl);
- if(res == CURLE_OK) {
- long code;
- res = curl_easy_getinfo(curl, CURLINFO_HTTP_CONNECTCODE, &code);
- if(!res && code)
- printf("The CONNECT response code: %03ld\\n", code);
+ /* typically CONNECT is used to do HTTPS over HTTP proxies */
+ curl_easy_setopt(curl, CURLOPT_PROXY, "http://127.0.0.1");
+ res = curl_easy_perform(curl);
+ if(res == CURLE_OK) {
+ long code;
+ res = curl_easy_getinfo(curl, CURLINFO_HTTP_CONNECTCODE, &code);
+ if(!res && code)
+ printf("The CONNECT response code: %03ld\\n", code);
+ }
+ curl_easy_cleanup(curl);
}
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
HTTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode res;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- res = curl_easy_perform(curl);
- if(res == CURLE_OK) {
- long http_version;
- curl_easy_getinfo(curl, CURLINFO_HTTP_VERSION, &http_version);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ res = curl_easy_perform(curl);
+ if(res == CURLE_OK) {
+ long http_version;
+ curl_easy_getinfo(curl, CURLINFO_HTTP_VERSION, &http_version);
+ }
+ curl_easy_cleanup(curl);
}
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- long sockfd; /* does not work on win64! */
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ long sockfd; /* does not work on win64! */
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* Do not do the transfer - only connect to host */
- curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
- res = curl_easy_perform(curl);
+ /* Do not do the transfer - only connect to host */
+ curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
+ res = curl_easy_perform(curl);
- /* Extract the socket from the curl handle */
- res = curl_easy_getinfo(curl, CURLINFO_LASTSOCKET, &sockfd);
+ /* Extract the socket from the curl handle */
+ res = curl_easy_getinfo(curl, CURLINFO_LASTSOCKET, &sockfd);
- if(res != CURLE_OK) {
- printf("Error: %s\\n", curl_easy_strerror(res));
- return 1;
+ if(res != CURLE_OK) {
+ printf("Error: %s\\n", curl_easy_strerror(res));
+ return 1;
+ }
}
}
.fi
All
.SH EXAMPLE
.nf
+int main(void)
{
char *ip;
+ CURLcode res;
+ CURL *curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
All
.SH EXAMPLE
.nf
+int main(void)
{
CURL *curl;
CURLcode res;
All
.SH EXAMPLE
.nf
-curl = curl_easy_init();
-if(curl) {
- double namelookup;
- curl_easy_setopt(curl, CURLOPT_URL, url);
- res = curl_easy_perform(curl);
- if(CURLE_OK == res) {
- res = curl_easy_getinfo(curl, CURLINFO_NAMELOOKUP_TIME, &namelookup);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ double namelookup;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ res = curl_easy_perform(curl);
if(CURLE_OK == res) {
- printf("Time: %.1f", namelookup);
+ res = curl_easy_getinfo(curl, CURLINFO_NAMELOOKUP_TIME, &namelookup);
+ if(CURLE_OK == res) {
+ printf("Time: %.1f", namelookup);
+ }
}
+ /* always cleanup */
+ curl_easy_cleanup(curl);
}
- /* always cleanup */
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-curl = curl_easy_init();
-if(curl) {
- curl_off_t namelookup;
- curl_easy_setopt(curl, CURLOPT_URL, url);
- res = curl_easy_perform(curl);
- if(CURLE_OK == res) {
- res = curl_easy_getinfo(curl, CURLINFO_NAMELOOKUP_TIME_T, &namelookup);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_off_t namelookup;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ res = curl_easy_perform(curl);
if(CURLE_OK == res) {
- printf("Time: %" CURL_FORMAT_CURL_OFF_T ".%06ld", namelookup / 1000000,
- (long)(namelookup % 1000000));
+ res = curl_easy_getinfo(curl, CURLINFO_NAMELOOKUP_TIME_T, &namelookup);
+ if(CURLE_OK == res) {
+ printf("Time: %" CURL_FORMAT_CURL_OFF_T ".%06ld", namelookup / 1000000,
+ (long)(namelookup % 1000000));
+ }
}
+ /* always cleanup */
+ curl_easy_cleanup(curl);
}
- /* always cleanup */
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode res;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
- res = curl_easy_perform(curl);
- if(res == CURLE_OK) {
- long connects;
- res = curl_easy_getinfo(curl, CURLINFO_NUM_CONNECTS, &connects);
- if(res)
- printf("It needed %d connects\\n", connects);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
+ res = curl_easy_perform(curl);
+ if(res == CURLE_OK) {
+ long connects;
+ res = curl_easy_getinfo(curl, CURLINFO_NUM_CONNECTS, &connects);
+ if(res)
+ printf("It needed %ld connects\\n", connects);
+ }
+ curl_easy_cleanup(curl);
}
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode res;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- res = curl_easy_perform(curl);
- if(res != CURLE_OK) {
- long error;
- res = curl_easy_getinfo(curl, CURLINFO_OS_ERRNO, &error);
- if(res && error) {
- printf("Errno: %ld\\n", error);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ res = curl_easy_perform(curl);
+ if(res != CURLE_OK) {
+ long error;
+ res = curl_easy_getinfo(curl, CURLINFO_OS_ERRNO, &error);
+ if(res && error) {
+ printf("Errno: %ld\\n", error);
+ }
}
+ curl_easy_cleanup(curl);
}
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-curl = curl_easy_init();
-if(curl) {
- double pretransfer;
- curl_easy_setopt(curl, CURLOPT_URL, url);
- res = curl_easy_perform(curl);
- if(CURLE_OK == res) {
- res = curl_easy_getinfo(curl, CURLINFO_PRETRANSFER_TIME, &pretransfer);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ double pretransfer;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ res = curl_easy_perform(curl);
if(CURLE_OK == res) {
- printf("Time: %.1f", pretransfer);
+ res = curl_easy_getinfo(curl, CURLINFO_PRETRANSFER_TIME, &pretransfer);
+ if(CURLE_OK == res) {
+ printf("Time: %.1f", pretransfer);
+ }
}
+ /* always cleanup */
+ curl_easy_cleanup(curl);
}
- /* always cleanup */
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-curl = curl_easy_init();
-if(curl) {
- curl_off_t pretransfer;
- curl_easy_setopt(curl, CURLOPT_URL, url);
- res = curl_easy_perform(curl);
- if(CURLE_OK == res) {
- res = curl_easy_getinfo(curl, CURLINFO_PRETRANSFER_TIME_T, &pretransfer);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_off_t pretransfer;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ res = curl_easy_perform(curl);
if(CURLE_OK == res) {
- printf("Time: %" CURL_FORMAT_CURL_OFF_T ".%06ld", pretransfer / 1000000,
- (long)(pretransfer % 1000000));
+ res = curl_easy_getinfo(curl, CURLINFO_PRETRANSFER_TIME_T, &pretransfer);
+ if(CURLE_OK == res) {
+ printf("Time: %" CURL_FORMAT_CURL_OFF_T ".%06ld\\n",
+ pretransfer / 1000000,
+ (long)(pretransfer % 1000000));
+ }
}
+ /* always cleanup */
+ curl_easy_cleanup(curl);
}
- /* always cleanup */
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
All network based ones
.SH EXAMPLE
.nf
+int main(void)
{
char *ip;
+ CURLcode res;
+ CURL *curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode res;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- res = curl_easy_perform(curl);
- if(res == CURLE_OK) {
- long port;
- res = curl_easy_getinfo(curl, CURLINFO_PRIMARY_PORT, &port);
- if(!res)
- printf("Connected to remote port: %ld\\n", port);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ res = curl_easy_perform(curl);
+ if(res == CURLE_OK) {
+ long port;
+ res = curl_easy_getinfo(curl, CURLINFO_PRIMARY_PORT, &port);
+ if(!res)
+ printf("Connected to remote port: %ld\\n", port);
+ }
+ curl_easy_cleanup(curl);
}
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- void *pointer = 0x2345454;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ void *pointer = (void *)0x2345454;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
- /* set the private pointer */
- curl_easy_setopt(curl, CURLOPT_PRIVATE, pointer);
- ret = curl_easy_perform(curl);
+ /* set the private pointer */
+ curl_easy_setopt(curl, CURLOPT_PRIVATE, pointer);
+ res = curl_easy_perform(curl);
- /* extract the private pointer again */
- ret = curl_easy_getinfo(curl, CURLINFO_PRIVATE, &pointer);
+ /* extract the private pointer again */
+ res = curl_easy_getinfo(curl, CURLINFO_PRIVATE, &pointer);
- curl_easy_cleanup(curl);
+ if(res)
+ printf("error: %s\\n", curl_easy_strerror(res));
+
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode res;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- res = curl_easy_perform(curl);
- if(res == CURLE_OK) {
- long protocol;
- curl_easy_getinfo(curl, CURLINFO_PROTOCOL, &protocol);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ res = curl_easy_perform(curl);
+ if(res == CURLE_OK) {
+ long protocol;
+ curl_easy_getinfo(curl, CURLINFO_PROTOCOL, &protocol);
+ }
+ curl_easy_cleanup(curl);
}
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
HTTP(S)
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- curl_easy_setopt(curl, CURLOPT_PROXY, "http://127.0.0.1:80");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ curl_easy_setopt(curl, CURLOPT_PROXY, "http://127.0.0.1:80");
- res = curl_easy_perform(curl);
+ res = curl_easy_perform(curl);
- if(!res) {
- /* extract the available proxy authentication types */
- long auth;
- res = curl_easy_getinfo(curl, CURLINFO_PROXYAUTH_AVAIL, &auth);
if(!res) {
- if(!auth)
- printf("No proxy auth available, perhaps no 407?\\n");
- else {
- printf("%s%s%s%s\\n",
- auth & CURLAUTH_BASIC ? "Basic ":"",
- auth & CURLAUTH_DIGEST ? "Digest ":"",
- auth & CURLAUTH_NEGOTIATE ? "Negotiate ":"",
- auth % CURLAUTH_NTLM ? "NTLM ":"");
+ /* extract the available proxy authentication types */
+ long auth;
+ res = curl_easy_getinfo(curl, CURLINFO_PROXYAUTH_AVAIL, &auth);
+ if(!res) {
+ if(!auth)
+ printf("No proxy auth available, perhaps no 407?\\n");
+ else {
+ printf("%s%s%s%s\\n",
+ auth & CURLAUTH_BASIC ? "Basic ":"",
+ auth & CURLAUTH_DIGEST ? "Digest ":"",
+ auth & CURLAUTH_NEGOTIATE ? "Negotiate ":"",
+ auth % CURLAUTH_NTLM ? "NTLM ":"");
+ }
}
}
+ curl_easy_cleanup(curl);
}
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
All that can be done over SOCKS
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode res;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- curl_easy_setopt(curl, CURLOPT_PROXY, "socks5://127.0.0.1");
- res = curl_easy_perform(curl);
- if(res == CURLE_PROXY) {
- long proxycode;
- res = curl_easy_getinfo(curl, CURLINFO_PROXY_ERROR, &proxycode);
- if(!res && proxycode)
- printf("The detailed proxy error: %ld\\n", proxycode);
+ curl_easy_setopt(curl, CURLOPT_PROXY, "socks5://127.0.0.1");
+ res = curl_easy_perform(curl);
+ if(res == CURLE_PROXY) {
+ long proxycode;
+ res = curl_easy_getinfo(curl, CURLINFO_PROXY_ERROR, &proxycode);
+ if(!res && proxycode)
+ printf("The detailed proxy error: %ld\\n", proxycode);
+ }
+ curl_easy_cleanup(curl);
}
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode res;
- long verifyresult;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- curl_easy_setopt(curl, CURLOPT_PROXY, "https://proxy:443");
- res = curl_easy_perform(curl);
- curl_easy_getinfo(curl, CURLINFO_PROXY_SSL_VERIFYRESULT, &verifyresult);
- printf("The peer verification said %s\\n", verifyresult?
- "fine":"BAAAD");
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ long verifyresult;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ curl_easy_setopt(curl, CURLOPT_PROXY, "https://proxy:443");
+ res = curl_easy_perform(curl);
+ if(res)
+ printf("error: %s\\n", curl_easy_strerror(res));
+ curl_easy_getinfo(curl, CURLINFO_PROXY_SSL_VERIFYRESULT, &verifyresult);
+ printf("The peer verification said %s\\n", verifyresult?
+ "fine" : "bad");
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP(S)
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode res;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
- res = curl_easy_perform(curl);
- if(res == CURLE_OK) {
- long redirects;
- curl_easy_getinfo(curl, CURLINFO_REDIRECT_COUNT, &redirects);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
+ res = curl_easy_perform(curl);
+ if(res == CURLE_OK) {
+ long redirects;
+ curl_easy_getinfo(curl, CURLINFO_REDIRECT_COUNT, &redirects);
+ }
+ curl_easy_cleanup(curl);
}
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-curl = curl_easy_init();
-if(curl) {
- double redirect;
- curl_easy_setopt(curl, CURLOPT_URL, url);
- res = curl_easy_perform(curl);
- if(CURLE_OK == res) {
- res = curl_easy_getinfo(curl, CURLINFO_REDIRECT_TIME, &redirect);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ double redirect;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ res = curl_easy_perform(curl);
if(CURLE_OK == res) {
- printf("Time: %.1f", redirect);
+ res = curl_easy_getinfo(curl, CURLINFO_REDIRECT_TIME, &redirect);
+ if(CURLE_OK == res) {
+ printf("Time: %.1f", redirect);
+ }
}
+ /* always cleanup */
+ curl_easy_cleanup(curl);
}
- /* always cleanup */
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-curl = curl_easy_init();
-if(curl) {
- curl_off_t redirect;
- curl_easy_setopt(curl, CURLOPT_URL, url);
- res = curl_easy_perform(curl);
- if(CURLE_OK == res) {
- res = curl_easy_getinfo(curl, CURLINFO_REDIRECT_TIME_T, &redirect);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_off_t redirect;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ res = curl_easy_perform(curl);
if(CURLE_OK == res) {
- printf("Time: %" CURL_FORMAT_CURL_OFF_T ".%06ld", redirect / 1000000,
- (long)(redirect % 1000000));
+ res = curl_easy_getinfo(curl, CURLINFO_REDIRECT_TIME_T, &redirect);
+ if(CURLE_OK == res) {
+ printf("Time: %" CURL_FORMAT_CURL_OFF_T ".%06ld", redirect / 1000000,
+ (long)(redirect % 1000000));
+ }
}
+ /* always cleanup */
+ curl_easy_cleanup(curl);
}
- /* always cleanup */
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
HTTP(S)
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode res;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- res = curl_easy_perform(curl);
- if(res == CURLE_OK) {
- char *url = NULL;
- curl_easy_getinfo(curl, CURLINFO_REDIRECT_URL, &url);
- if(url)
- printf("Redirect to: %s\\n", url);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ res = curl_easy_perform(curl);
+ if(res == CURLE_OK) {
+ char *url = NULL;
+ curl_easy_getinfo(curl, CURLINFO_REDIRECT_URL, &url);
+ if(url)
+ printf("Redirect to: %s\\n", url);
+ }
+ curl_easy_cleanup(curl);
}
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
HTTP(S)
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode res;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- curl_easy_setopt(curl, CURLOPT_REFERER, "https://example.org/referrer");
- res = curl_easy_perform(curl);
- if(res == CURLE_OK) {
- char *hdr = NULL;
- curl_easy_getinfo(curl, CURLINFO_REFERER, &hdr);
- if(hdr)
- printf("Referrer header: %s\\n", hdr);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ curl_easy_setopt(curl, CURLOPT_REFERER, "https://example.org/referrer");
+ res = curl_easy_perform(curl);
+ if(res == CURLE_OK) {
+ char *hdr = NULL;
+ curl_easy_getinfo(curl, CURLINFO_REFERER, &hdr);
+ if(hdr)
+ printf("Referrer header: %s\\n", hdr);
+ }
+ curl_easy_cleanup(curl);
}
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode res;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- res = curl_easy_perform(curl);
- if(res == CURLE_OK) {
- long req;
- res = curl_easy_getinfo(curl, CURLINFO_REQUEST_SIZE, &req);
- if(!res)
- printf("Request size: %ld bytes\\n", req);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ res = curl_easy_perform(curl);
+ if(res == CURLE_OK) {
+ long req;
+ res = curl_easy_getinfo(curl, CURLINFO_REQUEST_SIZE, &req);
+ if(!res)
+ printf("Request size: %ld bytes\\n", req);
+ }
+ curl_easy_cleanup(curl);
}
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
HTTP, FTP, SMTP and LDAP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode res;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- res = curl_easy_perform(curl);
- if(res == CURLE_OK) {
- long response_code;
- curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ res = curl_easy_perform(curl);
+ if(res == CURLE_OK) {
+ long response_code;
+ curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code);
+ }
+ curl_easy_cleanup(curl);
}
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
HTTP(S)
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode res;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- res = curl_easy_perform(curl);
- if(res == CURLE_OK) {
- curl_off_t wait = 0;
- curl_easy_getinfo(curl, CURLINFO_RETRY_AFTER, &wait);
- if(wait)
- printf("Wait for %" CURL_FORMAT_CURL_OFF_T " seconds\\n", wait);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ res = curl_easy_perform(curl);
+ if(res == CURLE_OK) {
+ curl_off_t wait = 0;
+ curl_easy_getinfo(curl, CURLINFO_RETRY_AFTER, &wait);
+ if(wait)
+ printf("Wait for %" CURL_FORMAT_CURL_OFF_T " seconds\\n", wait);
+ }
+ curl_easy_cleanup(curl);
}
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
RTSP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode res;
- curl_easy_setopt(curl, CURLOPT_URL, "rtsp://rtsp.example.com");
- res = curl_easy_perform(curl);
- if(res == CURLE_OK) {
- long cseq;
- curl_easy_getinfo(curl, CURLINFO_RTSP_CLIENT_CSEQ, &cseq);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "rtsp://rtsp.example.com");
+ res = curl_easy_perform(curl);
+ if(res == CURLE_OK) {
+ long cseq;
+ curl_easy_getinfo(curl, CURLINFO_RTSP_CLIENT_CSEQ, &cseq);
+ }
+ curl_easy_cleanup(curl);
}
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
RTSP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode res;
- curl_easy_setopt(curl, CURLOPT_URL, "rtsp://rtsp.example.com");
- res = curl_easy_perform(curl);
- if(res == CURLE_OK) {
- long cseq;
- curl_easy_getinfo(curl, CURLINFO_RTSP_CSEQ_RECV, &cseq);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "rtsp://rtsp.example.com");
+ res = curl_easy_perform(curl);
+ if(res == CURLE_OK) {
+ long cseq;
+ curl_easy_getinfo(curl, CURLINFO_RTSP_CSEQ_RECV, &cseq);
+ }
+ curl_easy_cleanup(curl);
}
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
RTSP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode res;
- curl_easy_setopt(curl, CURLOPT_URL, "rtsp://rtsp.example.com");
- res = curl_easy_perform(curl);
- if(res == CURLE_OK) {
- long cseq;
- curl_easy_getinfo(curl, CURLINFO_RTSP_SERVER_CSEQ, &cseq);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "rtsp://rtsp.example.com");
+ res = curl_easy_perform(curl);
+ if(res == CURLE_OK) {
+ long cseq;
+ curl_easy_getinfo(curl, CURLINFO_RTSP_SERVER_CSEQ, &cseq);
+ }
+ curl_easy_cleanup(curl);
}
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
RTSP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode res;
- curl_easy_setopt(curl, CURLOPT_URL, "rtsp://rtsp.example.com");
- res = curl_easy_perform(curl);
- if(res == CURLE_OK) {
- char *id;
- curl_easy_getinfo(curl, CURLINFO_RTSP_SESSION_ID, &id);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "rtsp://rtsp.example.com");
+ res = curl_easy_perform(curl);
+ if(res == CURLE_OK) {
+ char *id;
+ curl_easy_getinfo(curl, CURLINFO_RTSP_SESSION_ID, &id);
+ }
+ curl_easy_cleanup(curl);
}
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode res;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- res = curl_easy_perform(curl);
- if(res == CURLE_OK) {
- char *scheme = NULL;
- curl_easy_getinfo(curl, CURLINFO_SCHEME, &scheme);
- if(scheme)
- printf("scheme: %s\\n", scheme); /* scheme: HTTP */
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ res = curl_easy_perform(curl);
+ if(res == CURLE_OK) {
+ char *scheme = NULL;
+ curl_easy_getinfo(curl, CURLINFO_SCHEME, &scheme);
+ if(scheme)
+ printf("scheme: %s\\n", scheme); /* scheme: HTTP */
+ }
+ curl_easy_cleanup(curl);
}
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* Perform the request */
- res = curl_easy_perform(curl);
+ /* Perform the request */
+ res = curl_easy_perform(curl);
- if(!res) {
- /* check the size */
- double dl;
- res = curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD, &dl);
if(!res) {
- printf("Downloaded %.0f bytes\\n", cl);
+ /* check the size */
+ double dl;
+ res = curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD, &dl);
+ if(!res) {
+ printf("Downloaded %.0f bytes\\n", dl);
+ }
}
}
}
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* Perform the request */
- res = curl_easy_perform(curl);
+ /* Perform the request */
+ res = curl_easy_perform(curl);
- if(!res) {
- /* check the size */
- curl_off_t dl;
- res = curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD_T, &dl);
if(!res) {
- printf("Downloaded %" CURL_FORMAT_CURL_OFF_T " bytes\\n", dl);
+ /* check the size */
+ curl_off_t dl;
+ res = curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD_T, &dl);
+ if(!res) {
+ printf("Downloaded %" CURL_FORMAT_CURL_OFF_T " bytes\\n", dl);
+ }
}
}
}
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* Perform the request */
- res = curl_easy_perform(curl);
+ /* Perform the request */
+ res = curl_easy_perform(curl);
- if(!res) {
- double ul;
- res = curl_easy_getinfo(curl, CURLINFO_SIZE_UPLOAD, &ul);
if(!res) {
- printf("Uploaded %.0f bytes\\n", ul);
+ double ul;
+ res = curl_easy_getinfo(curl, CURLINFO_SIZE_UPLOAD, &ul);
+ if(!res) {
+ printf("Uploaded %.0f bytes\\n", ul);
+ }
}
}
}
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* Perform the request */
- res = curl_easy_perform(curl);
+ /* Perform the request */
+ res = curl_easy_perform(curl);
- if(!res) {
- curl_off_t ul;
- res = curl_easy_getinfo(curl, CURLINFO_SIZE_UPLOAD_T, &ul);
if(!res) {
- printf("Uploaded %" CURL_FORMAT_CURL_OFF_T " bytes\\n", ul);
+ curl_off_t ul;
+ res = curl_easy_getinfo(curl, CURLINFO_SIZE_UPLOAD_T, &ul);
+ if(!res) {
+ printf("Uploaded %" CURL_FORMAT_CURL_OFF_T " bytes\\n", ul);
+ }
}
}
}
.SH PROTOCOLS
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* Perform the request */
- res = curl_easy_perform(curl);
+ /* Perform the request */
+ res = curl_easy_perform(curl);
- if(!res) {
- double speed;
- res = curl_easy_getinfo(curl, CURLINFO_SPEED_DOWNLOAD, &speed);
if(!res) {
- printf("Download speed %.0f bytes/sec\\n", speed);
+ double speed;
+ res = curl_easy_getinfo(curl, CURLINFO_SPEED_DOWNLOAD, &speed);
+ if(!res) {
+ printf("Download speed %.0f bytes/sec\\n", speed);
+ }
}
}
}
.SH PROTOCOLS
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* Perform the request */
- res = curl_easy_perform(curl);
+ /* Perform the request */
+ res = curl_easy_perform(curl);
- if(!res) {
- curl_off_t speed;
- res = curl_easy_getinfo(curl, CURLINFO_SPEED_DOWNLOAD_T, &speed);
if(!res) {
- printf("Download speed %" CURL_FORMAT_CURL_OFF_T " bytes/sec\\n", speed);
+ curl_off_t speed;
+ res = curl_easy_getinfo(curl, CURLINFO_SPEED_DOWNLOAD_T, &speed);
+ if(!res) {
+ printf("Download speed %" CURL_FORMAT_CURL_OFF_T " bytes/sec\\n",
+ speed);
+ }
}
}
}
.SH PROTOCOLS
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* Perform the request */
- res = curl_easy_perform(curl);
+ /* Perform the request */
+ res = curl_easy_perform(curl);
- if(!res) {
- double speed;
- res = curl_easy_getinfo(curl, CURLINFO_SPEED_UPLOAD, &speed);
if(!res) {
- printf("Upload speed %.0f bytes/sec\\n", speed);
+ double speed;
+ res = curl_easy_getinfo(curl, CURLINFO_SPEED_UPLOAD, &speed);
+ if(!res) {
+ printf("Upload speed %.0f bytes/sec\\n", speed);
+ }
}
}
}
.SH PROTOCOLS
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* Perform the request */
- res = curl_easy_perform(curl);
+ /* Perform the request */
+ res = curl_easy_perform(curl);
- if(!res) {
- curl_off_t speed;
- res = curl_easy_getinfo(curl, CURLINFO_SPEED_UPLOAD_T, &speed);
if(!res) {
- printf("Upload speed %" CURL_FORMAT_CURL_OFF_T " bytes/sec\\n", speed);
+ curl_off_t speed;
+ res = curl_easy_getinfo(curl, CURLINFO_SPEED_UPLOAD_T, &speed);
+ if(!res) {
+ printf("Upload speed %" CURL_FORMAT_CURL_OFF_T " bytes/sec\\n", speed);
+ }
}
}
}
All TLS based ones.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode res;
- struct curl_slist *engines;
- res = curl_easy_getinfo(curl, CURLINFO_SSL_ENGINES, &engines);
- if((res == CURLE_OK) && engines) {
- /* we have a list, free it when done using it */
- curl_slist_free_all(engines);
- }
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ struct curl_slist *engines;
+ res = curl_easy_getinfo(curl, CURLINFO_SSL_ENGINES, &engines);
+ if((res == CURLE_OK) && engines) {
+ /* we have a list, free it when done using it */
+ curl_slist_free_all(engines);
+ }
- curl_easy_cleanup(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All using TLS
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode res;
- long verifyresult;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- res = curl_easy_perform(curl);
- curl_easy_getinfo(curl, CURLINFO_SSL_VERIFYRESULT, &verifyresult);
- printf("The peer verification said %s\\n", verifyresult?
- "BAAAD":"fine");
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ long verifyresult;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ res = curl_easy_perform(curl);
+ if(res)
+ printf("error: %s\\n", curl_easy_strerror(res));
+ curl_easy_getinfo(curl, CURLINFO_SSL_VERIFYRESULT, &verifyresult);
+ printf("The peer verification said %s\\n", verifyresult?
+ "BAAAD":"fine");
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-curl = curl_easy_init();
-if(curl) {
- double start;
- curl_easy_setopt(curl, CURLOPT_URL, url);
- res = curl_easy_perform(curl);
- if(CURLE_OK == res) {
- res = curl_easy_getinfo(curl, CURLINFO_STARTTRANSFER_TIME, &start);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ double start;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ res = curl_easy_perform(curl);
if(CURLE_OK == res) {
- printf("Time: %.1f", start);
+ res = curl_easy_getinfo(curl, CURLINFO_STARTTRANSFER_TIME, &start);
+ if(CURLE_OK == res) {
+ printf("Time: %.1f", start);
+ }
}
+ /* always cleanup */
+ curl_easy_cleanup(curl);
}
- /* always cleanup */
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-curl = curl_easy_init();
-if(curl) {
- curl_off_t start;
- curl_easy_setopt(curl, CURLOPT_URL, url);
- res = curl_easy_perform(curl);
- if(CURLE_OK == res) {
- res = curl_easy_getinfo(curl, CURLINFO_STARTTRANSFER_TIME_T, &start);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_off_t start;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ res = curl_easy_perform(curl);
if(CURLE_OK == res) {
- printf("Time: %" CURL_FORMAT_CURL_OFF_T ".%06ld", start / 1000000,
- (long)(start % 1000000));
+ res = curl_easy_getinfo(curl, CURLINFO_STARTTRANSFER_TIME_T, &start);
+ if(CURLE_OK == res) {
+ printf("Time: %" CURL_FORMAT_CURL_OFF_T ".%06ld", start / 1000000,
+ (long)(start % 1000000));
+ }
}
+ /* always cleanup */
+ curl_easy_cleanup(curl);
}
- /* always cleanup */
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
All TLS-based
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode res;
- struct curl_tlssessioninfo *tls;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- res = curl_easy_perform(curl);
- curl_easy_getinfo(curl, CURLINFO_TLS_SESSION, &tls);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ struct curl_tlssessioninfo *tls;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ res = curl_easy_perform(curl);
+ if(res)
+ printf("error: %s\\n", curl_easy_strerror(res));
+ curl_easy_getinfo(curl, CURLINFO_TLS_SESSION, &tls);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
CURLcode res = curl_easy_getinfo(curl, CURLINFO_TLS_SSL_PTR, &info);
if(info && !res) {
if(CURLSSLBACKEND_OPENSSL == info->backend) {
- printf("OpenSSL ver. %s\\n", SSL_get_version((SSL*)info->internals));
+ printf("OpenSSL ver. %s\\n", SSL_get_version((SSL*)info->internals));
}
}
return size * nmemb;
}
-int main(int argc, char** argv)
+int main(int argc, char **argv)
{
CURLcode res;
curl = curl_easy_init();
All
.SH EXAMPLE
.nf
-curl = curl_easy_init();
-if(curl) {
- double total;
- curl_easy_setopt(curl, CURLOPT_URL, url);
- res = curl_easy_perform(curl);
- if(CURLE_OK == res) {
- res = curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &total);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ double total;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ res = curl_easy_perform(curl);
if(CURLE_OK == res) {
- printf("Time: %.1f", total);
+ res = curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &total);
+ if(CURLE_OK == res) {
+ printf("Time: %.1f", total);
+ }
}
+ /* always cleanup */
+ curl_easy_cleanup(curl);
}
- /* always cleanup */
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-curl = curl_easy_init();
-if(curl) {
- curl_off_t total;
- curl_easy_setopt(curl, CURLOPT_URL, url);
- res = curl_easy_perform(curl);
- if(CURLE_OK == res) {
- res = curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME_T, &total);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_off_t total;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ res = curl_easy_perform(curl);
if(CURLE_OK == res) {
- printf("Time: %" CURL_FORMAT_CURL_OFF_T ".%06ld", total / 1000000,
- (long)(total % 1000000));
+ res = curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME_T, &total);
+ if(CURLE_OK == res) {
+ printf("Time: %" CURL_FORMAT_CURL_OFF_T ".%06ld", total / 1000000,
+ (long)(total % 1000000));
+ }
}
+ /* always cleanup */
+ curl_easy_cleanup(curl);
}
- /* always cleanup */
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* Perform the request */
- res = curl_easy_perform(curl);
+ /* Perform the request */
+ res = curl_easy_perform(curl);
- if(!res) {
- curl_off_t xfer_id;
- res = curl_easy_getinfo(curl, CURLINFO_XFER_ID, &xfer_id);
if(!res) {
- printf("Transfer ID: %" CURL_FORMAT_CURL_OFF_T "\\n", xfer_id);
+ curl_off_t xfer_id;
+ res = curl_easy_getinfo(curl, CURLINFO_XFER_ID, &xfer_id);
+ if(!res) {
+ printf("Transfer ID: %" CURL_FORMAT_CURL_OFF_T "\\n", xfer_id);
+ }
}
}
}
HTTP(S)
.SH EXAMPLE
.nf
-CURLM *m = curl_multi_init();
-long maxchunk = 10000;
-curl_multi_setopt(m, CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE, maxchunk);
+int main(void)
+{
+ CURLM *m = curl_multi_init();
+ long maxchunk = 10000;
+ curl_multi_setopt(m, CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE, maxchunk);
+}
.fi
.SH AVAILABILITY
Added in 7.30.0
HTTP(S)
.SH EXAMPLE
.nf
-CURLM *m = curl_multi_init();
-long maxlength = 10000;
-curl_multi_setopt(m, CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE, maxlength);
+int main(void)
+{
+ CURLM *m = curl_multi_init();
+ long maxlength = 10000;
+ curl_multi_setopt(m, CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE, maxlength);
+}
.fi
.SH AVAILABILITY
Added in 7.30.0
All
.SH EXAMPLE
.nf
-CURLM *m = curl_multi_init();
-/* only keep 10 connections in the cache */
-curl_multi_setopt(m, CURLMOPT_MAXCONNECTS, 10L);
+int main(void)
+{
+ CURLM *m = curl_multi_init();
+ /* only keep 10 connections in the cache */
+ curl_multi_setopt(m, CURLMOPT_MAXCONNECTS, 10L);
+}
.fi
.SH AVAILABILITY
Added in 7.16.3
All
.SH EXAMPLE
.nf
+int main(void)
+{
CURLM *m = curl_multi_init();
/* max concurrent streams 200 */
curl_multi_setopt(m, CURLMOPT_MAX_CONCURRENT_STREAMS, 200L);
+}
.fi
.SH AVAILABILITY
Added in 7.67.0
HTTP(S)
.SH EXAMPLE
.nf
-CURLM *m = curl_multi_init();
-/* do no more than 2 connections per host */
-curl_multi_setopt(m, CURLMOPT_MAX_HOST_CONNECTIONS, 2L);
+int main(void)
+{
+ CURLM *m = curl_multi_init();
+ /* do no more than 2 connections per host */
+ curl_multi_setopt(m, CURLMOPT_MAX_HOST_CONNECTIONS, 2L);
+}
.fi
.SH AVAILABILITY
Added in 7.30.0
HTTP(S)
.SH EXAMPLE
.nf
-CURLM *m = curl_multi_init();
-/* set a more conservative pipe length */
-curl_multi_setopt(m, CURLMOPT_MAX_PIPELINE_LENGTH, 3L);
+int main(void)
+{
+ CURLM *m = curl_multi_init();
+ /* set a more conservative pipe length */
+ curl_multi_setopt(m, CURLMOPT_MAX_PIPELINE_LENGTH, 3L);
+}
.fi
.SH AVAILABILITY
Added in 7.30.0
All
.SH EXAMPLE
.nf
-CURLM *m = curl_multi_init();
-/* never do more than 15 connections */
-curl_multi_setopt(m, CURLMOPT_MAX_TOTAL_CONNECTIONS, 15L);
+int main(void)
+{
+ CURLM *m = curl_multi_init();
+ /* never do more than 15 connections */
+ curl_multi_setopt(m, CURLMOPT_MAX_TOTAL_CONNECTIONS, 15L);
+}
.fi
.SH AVAILABILITY
Added in 7.30.0
HTTP(S)
.SH EXAMPLE
.nf
-CURLM *m = curl_multi_init();
-/* try HTTP/2 multiplexing */
-curl_multi_setopt(m, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX);
+int main(void)
+{
+ CURLM *m = curl_multi_init();
+ /* try HTTP/2 multiplexing */
+ curl_multi_setopt(m, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX);
+}
.fi
.SH AVAILABILITY
Added in 7.16.0. Multiplex support bit added in 7.43.0. HTTP/1 Pipelining
.SH PROTOCOLS
.SH EXAMPLE
.nf
- char *server_block_list[] =
- {
- "Microsoft-IIS/6.0",
- "nginx/0.8.54",
- NULL
- };
-
+static char *server_block_list[] =
+{
+ "Microsoft-IIS/6.0",
+ "nginx/0.8.54",
+ NULL
+};
+int main(void)
+{
+ CURLM *m = curl_multi_init();
curl_multi_setopt(m, CURLMOPT_PIPELINING_SERVER_BL, server_block_list);
+}
.fi
.SH AVAILABILITY
Added in 7.30.0
HTTP(S)
.SH EXAMPLE
.nf
- char *site_block_list[] =
- {
- "www.haxx.se",
- "www.example.com:1234",
- NULL
- };
+static char *site_block_list[] =
+{
+ "www.haxx.se",
+ "www.example.com:1234",
+ NULL
+};
+int main(void)
+{
+ CURLM *m = curl_multi_init();
curl_multi_setopt(m, CURLMOPT_PIPELINING_SITE_BL, site_block_list);
+}
.fi
.SH AVAILABILITY
Added in 7.30.0
HTTP(S)
.SH EXAMPLE
.nf
+#include <string.h>
+
/* only allow pushes for file names starting with "push-" */
int push_callback(CURL *parent,
CURL *easy,
return CURL_PUSH_DENY;
}
-curl_multi_setopt(multi, CURLMOPT_PUSHFUNCTION, push_callback);
-curl_multi_setopt(multi, CURLMOPT_PUSHDATA, &counter);
+int main(void)
+{
+ int counter;
+ CURLM *multi = curl_multi_init();
+ curl_multi_setopt(multi, CURLMOPT_PUSHFUNCTION, push_callback);
+ curl_multi_setopt(multi, CURLMOPT_PUSHDATA, &counter);
+}
.fi
.SH AVAILABILITY
Added in 7.44.0
HTTP(S) (HTTP/2 only)
.SH EXAMPLE
.nf
+#include <string.h>
+
/* only allow pushes for file names starting with "push-" */
int push_callback(CURL *parent,
CURL *easy,
return CURL_PUSH_DENY;
}
-curl_multi_setopt(multi, CURLMOPT_PUSHFUNCTION, push_callback);
-curl_multi_setopt(multi, CURLMOPT_PUSHDATA, &counter);
+int main(void)
+{
+ int counter;
+ CURLM *multi = curl_multi_init();
+ curl_multi_setopt(multi, CURLMOPT_PUSHFUNCTION, push_callback);
+ curl_multi_setopt(multi, CURLMOPT_PUSHDATA, &counter);
+}
.fi
.SH AVAILABILITY
Added in 7.44.0
All
.SH EXAMPLE
.nf
+struct priv {
+ void *ours;
+};
+
static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp)
{
- GlobalInfo *g = (GlobalInfo*) cbp;
- SockInfo *fdp = (SockInfo*) sockp;
+ struct priv *p = sockp;
+ printf("my ptr: %p\\n", p->ours);
if(what == CURL_POLL_REMOVE) {
- remsock(fdp);
+ /* remove the socket from our collection */
+ }
+ if(what & CURL_POLL_IN) {
+ /* wait for read on this socket */
}
- else {
- if(!fdp) {
- addsock(s, e, what, g);
- }
- else {
- setsock(fdp, s, e, what, g);
- }
+ if(what & CURL_POLL_OUT) {
+ /* wait for write on this socket */
}
+
return 0;
}
-main()
+int main(void)
{
- GlobalInfo setup;
+ struct priv setup;
+ CURLM *multi = curl_multi_init();
/* ... use socket callback and custom pointer */
curl_multi_setopt(multi, CURLMOPT_SOCKETFUNCTION, sock_cb);
curl_multi_setopt(multi, CURLMOPT_SOCKETDATA, &setup);
All
.SH EXAMPLE
.nf
+struct priv {
+ void *ours;
+};
+
static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp)
{
- GlobalInfo *g = cbp;
- SockInfo *fdp = sockp;
+ struct priv *p = sockp;
+ printf("our ptr: %p\\n", p->ours);
if(what == CURL_POLL_REMOVE) {
- remsock(fdp);
+ /* remove the socket from our collection */
+ }
+ if(what & CURL_POLL_IN) {
+ /* wait for read on this socket */
}
- else {
- if(!fdp) {
- addsock(s, e, what, g);
- }
- else {
- setsock(fdp, s, e, what, g);
- }
+ if(what & CURL_POLL_OUT) {
+ /* wait for write on this socket */
}
+
return 0;
}
-main()
+int main(void)
{
- GlobalInfo setup;
+ struct priv setup;
+ CURLM *multi = curl_multi_init();
/* ... use socket callback and custom pointer */
curl_multi_setopt(multi, CURLMOPT_SOCKETFUNCTION, sock_cb);
curl_multi_setopt(multi, CURLMOPT_SOCKETDATA, &setup);
All
.SH EXAMPLE
.nf
-static gboolean timeout_cb(gpointer user_data)
-{
- int running;
- if(user_data) {
- g_free(user_data);
- curl_multi_setopt(curl_handle, CURLMOPT_TIMERDATA, NULL);
- }
- curl_multi_socket_action(multi, CURL_SOCKET_TIMEOUT, 0, &running);
- return G_SOURCE_REMOVE;
-}
+struct priv {
+ void *custom;
+};
static int timerfunc(CURLM *multi, long timeout_ms, void *clientp)
{
- guint *id = clientp;
-
- if(id)
- g_source_remove(*id);
+ struct priv *mydata = clientp;
+ printf("our ptr: %p\\n", mydata->custom);
- /* -1 means we should just delete our timer. */
- if(timeout_ms == -1) {
- g_free(id);
- id = NULL;
- }
- else {
- if(!id)
- id = g_new(guint, 1);
- *id = g_timeout_add(timeout_ms, timeout_cb, id);
- }
- current_timer = id;
- return 0;
+ if(timeout_ms) {
+ /* this is the new single timeout to wait for */
+ }
+ else {
+ /* delete the timeout, nothing to wait for now */
+ }
}
-curl_multi_setopt(multi, CURLMOPT_TIMERFUNCTION, timerfunc);
+int main(void)
+{
+ struct priv mydata;
+ CURLM *multi = curl_multi_init();
+ curl_multi_setopt(multi, CURLMOPT_TIMERFUNCTION, timerfunc);
+ curl_multi_setopt(multi, CURLMOPT_TIMERDATA, &mydata);
+}
.fi
.SH AVAILABILITY
Added in 7.16.0
All
.SH EXAMPLE
.nf
-static gboolean timeout_cb(gpointer user_data)
-{
- int running;
- if(user_data) {
- g_free(user_data);
- curl_multi_setopt(curl_handle, CURLMOPT_TIMERDATA, NULL);
- }
- curl_multi_socket_action(multi, CURL_SOCKET_TIMEOUT, 0, &running);
- return G_SOURCE_REMOVE;
-}
+struct priv {
+ void *custom;
+};
static int timerfunc(CURLM *multi, long timeout_ms, void *clientp)
{
- guint *id = clientp;
-
- if(id)
- g_source_remove(*id);
+ struct priv *mydata = clientp;
+ printf("our ptr: %p\\n", mydata->custom);
- /* -1 means we should just delete our timer. */
- if(timeout_ms == -1) {
- g_free(id);
- id = NULL;
- }
- else {
- if(!id)
- id = g_new(guint, 1);
- *id = g_timeout_add(timeout_ms, timeout_cb, id);
- }
- current_timer = id;
- return 0;
+ if(timeout_ms) {
+ /* this is the new single timeout to wait for */
+ }
+ else {
+ /* delete the timeout, nothing to wait for now */
+ }
}
-curl_multi_setopt(multi, CURLMOPT_TIMERFUNCTION, timerfunc);
+int main(void)
+{
+ struct priv mydata;
+ CURLM *multi = curl_multi_init();
+ curl_multi_setopt(multi, CURLMOPT_TIMERFUNCTION, timerfunc);
+ curl_multi_setopt(multi, CURLMOPT_TIMERDATA, &mydata);
+}
.fi
.SH AVAILABILITY
Added in 7.16.0
All
.SH EXAMPLE
.nf
- curl_easy_setopt(curl_handle, CURLOPT_ABSTRACT_UNIX_SOCKET, "/tmp/foo.sock");
- curl_easy_setopt(curl_handle, CURLOPT_URL, "http://localhost/");
-.fi
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ 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);
+ }
+}
+.fi
.SH AVAILABILITY
Added in 7.53.0.
.SH RETURN VALUE
FTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/path/file");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/path/file");
- /* wait no more than 5 seconds for FTP server responses */
- curl_easy_setopt(curl, CURLOPT_ACCEPTTIMEOUT_MS, 5000L);
+ /* wait no more than 5 seconds for FTP server responses */
+ curl_easy_setopt(curl, CURLOPT_ACCEPTTIMEOUT_MS, 5000L);
- curl_easy_perform(curl);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* enable all supported built-in compressions */
- curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, "");
+ /* enable all supported built-in compressions */
+ curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, "");
- /* Perform the request */
- curl_easy_perform(curl);
+ /* Perform the request */
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
All, when using IPv6
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode ret;
- long my_scope_id;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- my_scope_id = if_nametoindex("eth0");
- curl_easy_setopt(curl, CURLOPT_ADDRESS_SCOPE, my_scope_id);
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+#include <net/if.h> /* for if_nametoindex() */
+
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode ret;
+ long my_scope_id;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ my_scope_id = if_nametoindex("eth0");
+ curl_easy_setopt(curl, CURLOPT_ADDRESS_SCOPE, my_scope_id);
+ ret = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTPS
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_ALTSVC_CTRL, CURLALTSVC_H1);
- curl_easy_setopt(curl, CURLOPT_ALTSVC, "altsvc-cache.txt");
- curl_easy_perform(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_ALTSVC_CTRL, CURLALTSVC_H1);
+ curl_easy_setopt(curl, CURLOPT_ALTSVC, "altsvc-cache.txt");
+ curl_easy_perform(curl);
+ }
}
.fi
.SH "FILE FORMAT"
HTTPS
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_ALTSVC_CTRL, (long)CURLALTSVC_H1);
- curl_easy_setopt(curl, CURLOPT_ALTSVC, "altsvc-cache.txt");
- curl_easy_perform(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_ALTSVC_CTRL, (long)CURLALTSVC_H1);
+ curl_easy_setopt(curl, CURLOPT_ALTSVC, "altsvc-cache.txt");
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
FTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
- 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_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);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
- /* follow redirects */
- curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
+ /* follow redirects */
+ curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
- /* set Referer: automatically when following redirects */
- curl_easy_setopt(curl, CURLOPT_AUTOREFERER, 1L);
+ /* set Referer: automatically when following redirects */
+ curl_easy_setopt(curl, CURLOPT_AUTOREFERER, 1L);
- ret = curl_easy_perform(curl);
+ res = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
+int main(void)
+{
+ CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL,
- "https://service.region.example.com/uri");
- curl_easy_setopt(c, CURLOPT_AWS_SIGV4, "provider1:provider2");
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL,
+ "https://service.region.example.com/uri");
+ curl_easy_setopt(curl, CURLOPT_AWS_SIGV4, "provider1:provider2");
- /* service and region can also be set in CURLOPT_AWS_SIGV4 */
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/uri");
- curl_easy_setopt(c, CURLOPT_AWS_SIGV4,
- "provider1:provider2:region:service");
+ /* service and region can also be set in CURLOPT_AWS_SIGV4 */
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/uri");
+ curl_easy_setopt(curl, CURLOPT_AWS_SIGV4,
+ "provider1:provider2:region:service");
- curl_easy_setopt(c, CURLOPT_USERPWD, "MY_ACCESS_KEY:MY_SECRET_KEY");
- curl_easy_perform(curl);
+ curl_easy_setopt(curl, CURLOPT_USERPWD, "MY_ACCESS_KEY:MY_SECRET_KEY");
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "sftp://example.com/foo.bin");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "sftp://example.com/foo.bin");
- /* ask libcurl to allocate a larger receive buffer */
- curl_easy_setopt(curl, CURLOPT_BUFFERSIZE, 120000L);
+ /* ask libcurl to allocate a larger receive buffer */
+ curl_easy_setopt(curl, CURLOPT_BUFFERSIZE, 120000L);
- ret = curl_easy_perform(curl);
+ res = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_CAINFO, "/etc/certs/cabundle.pem");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_CAINFO, "/etc/certs/cabundle.pem");
+ curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc.
.SH EXAMPLE
.nf
-char *strpem; /* strpem must point to a PEM string */
-CURL *curl = curl_easy_init();
-if(curl) {
- struct curl_blob blob;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- blob.data = strpem;
- blob.len = strlen(strpem);
- blob.flags = CURL_BLOB_COPY;
- curl_easy_setopt(curl, CURLOPT_CAINFO_BLOB, &blob);
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+#include <string.h>
+
+int main(void)
+{
+ char *strpem; /* strpem must point to a PEM string */
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ struct curl_blob blob;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ blob.data = strpem;
+ blob.len = strlen(strpem);
+ blob.flags = CURL_BLOB_COPY;
+ curl_easy_setopt(curl, CURLOPT_CAINFO_BLOB, &blob);
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_CAPATH, "/etc/cert-dir");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_CAPATH, "/etc/cert-dir");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ 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);
+ /* only reuse certificate stores for a short time */
+ curl_easy_setopt(curl, CURLOPT_CA_CACHE_TIMEOUT, 60L);
- ret = curl_easy_perform(curl);
+ res = curl_easy_perform(curl);
- /* in this second request, the cache is not used if more than
- sixty seconds passed since the previous connection */
- ret = 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);
- curl_easy_cleanup(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All TLS-based
.SH EXAMPLE
.nf
-curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://www.example.com/");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://www.example.com/");
- /* connect to any HTTPS site, trusted or not */
- curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
- curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
+ /* connect to any HTTPS site, trusted or not */
+ curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
+ curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
- curl_easy_setopt(curl, CURLOPT_CERTINFO, 1L);
+ curl_easy_setopt(curl, CURLOPT_CERTINFO, 1L);
- res = curl_easy_perform(curl);
+ res = curl_easy_perform(curl);
- if (!res) {
- struct curl_certinfo *ci;
- res = curl_easy_getinfo(curl, CURLINFO_CERTINFO, &ci);
+ if(!res) {
+ struct curl_certinfo *ci;
+ res = curl_easy_getinfo(curl, CURLINFO_CERTINFO, &ci);
- if (!res) {
- printf("%d certs!\\n", ci->num_of_certs);
+ if(!res) {
+ int i;
+ printf("%d certs!\\n", ci->num_of_certs);
- for(i = 0; i < ci->num_of_certs; i++) {
- struct curl_slist *slist;
+ for(i = 0; i < ci->num_of_certs; i++) {
+ struct curl_slist *slist;
- for(slist = ci->certinfo[i]; slist; slist = slist->next)
- printf("%s\\n", slist->data);
+ for(slist = ci->certinfo[i]; slist; slist = slist->next)
+ printf("%s\\n", slist->data);
+ }
}
}
+ curl_easy_cleanup(curl);
}
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
FTP
.SH EXAMPLE
.nf
+#include <stdio.h>
+
+struct callback_data {
+ FILE *output;
+};
+
static long file_is_coming(struct curl_fileinfo *finfo,
- struct callback_data *data,
+ void *ptr,
int remains)
{
+ struct callback_data *data = ptr;
printf("%3d %40s %10luB ", remains, finfo->filename,
(unsigned long)finfo->size);
/* data for callback */
struct callback_data callback_info;
+ CURL *curl = curl_easy_init();
+
/* callback is called before download of concrete file started */
curl_easy_setopt(curl, CURLOPT_CHUNK_BGN_FUNCTION, file_is_coming);
curl_easy_setopt(curl, CURLOPT_CHUNK_DATA, &callback_info);
FTP
.SH EXAMPLE
.nf
+#include <stdio.h>
+
+struct callback_data {
+ FILE *output;
+};
+
static long file_is_coming(struct curl_fileinfo *finfo,
- struct callback_data *data,
+ void *ptr,
int remains)
{
+ struct callback_data *data = ptr;
printf("%3d %40s %10luB ", remains, finfo->filename,
(unsigned long)finfo->size);
/* data for callback */
struct callback_data callback_info;
+ CURL *curl = curl_easy_init();
+
/* callback is called before download of concrete file started */
curl_easy_setopt(curl, CURLOPT_CHUNK_BGN_FUNCTION, file_is_coming);
curl_easy_setopt(curl, CURLOPT_CHUNK_DATA, &callback_info);
FTP
.SH EXAMPLE
.nf
+#include <stdio.h>
+
+struct callback_data {
+ FILE *output;
+};
+
static long file_is_downloaded(struct callback_data *data)
{
if(data->output) {
{
/* data for callback */
struct callback_data callback_info;
+
+ CURL *curl = curl_easy_init();
+
curl_easy_setopt(curl, CURLOPT_CHUNK_END_FUNCTION, file_is_downloaded);
curl_easy_setopt(curl, CURLOPT_CHUNK_DATA, &callback_info);
}
All except file:
.SH EXAMPLE
.nf
+struct priv {
+ void *custom;
+};
+
static int closesocket(void *clientp, curl_socket_t item)
{
+ struct priv *my = clientp;
+ printf("our ptr: %p\\n", my->custom);
+
printf("libcurl wants to close %d now\\n", (int)item);
return 0;
}
-/* call this function to close sockets */
-curl_easy_setopt(curl, CURLOPT_CLOSESOCKETFUNCTION, closesocket);
-curl_easy_setopt(curl, CURLOPT_CLOSESOCKETDATA, &sockfd);
+int main(void)
+{
+ struct priv myown;
+ CURL *curl = curl_easy_init();
+
+ /* 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);
+}
.fi
.SH AVAILABILITY
Added in 7.21.7
All
.SH EXAMPLE
.nf
+struct priv {
+ void *custom;
+};
+
static int closesocket(void *clientp, curl_socket_t item)
{
+ struct priv *my = clientp;
+ printf("our ptr: %p\\n", my->custom);
+
printf("libcurl wants to close %d now\\n", (int)item);
return 0;
}
-/* call this function to close sockets */
-curl_easy_setopt(curl, CURLOPT_CLOSESOCKETFUNCTION, closesocket);
-curl_easy_setopt(curl, CURLOPT_CLOSESOCKETDATA, &sockfd);
+int main(void)
+{
+ struct priv myown;
+ CURL *curl = curl_easy_init();
+
+ /* 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);
+}
.fi
.SH AVAILABILITY
Added in 7.21.7
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* complete connection within 10 seconds */
- curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10L);
+ /* complete connection within 10 seconds */
+ curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10L);
- curl_easy_perform(curl);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* complete connection within 10000 milliseconds */
- curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT_MS, 10000L);
+ /* complete connection within 10000 milliseconds */
+ curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT_MS, 10000L);
- curl_easy_perform(curl);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP, SMTP, POP3 and IMAP. For WS and WSS starting in 7.86.0.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode ret;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
- ret = curl_easy_perform(curl);
- if(ret == CURLE_OK) {
- /* only connected! */
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode ret;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
+ ret = curl_easy_perform(curl);
+ if(ret == CURLE_OK) {
+ /* only connected! */
+ }
}
}
.fi
All
.SH EXAMPLE
.nf
-CURL *curl;
-struct curl_slist *connect_to = NULL;
-connect_to = curl_slist_append(NULL, "example.com::server1.example.com:");
+int main(void)
+{
+ CURL *curl;
+ struct curl_slist *connect_to = NULL;
+ connect_to = curl_slist_append(NULL, "example.com::server1.example.com:");
-curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_CONNECT_TO, connect_to);
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_CONNECT_TO, connect_to);
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- curl_easy_perform(curl);
+ curl_easy_perform(curl);
- /* always cleanup */
- curl_easy_cleanup(curl);
-}
+ /* always cleanup */
+ curl_easy_cleanup(curl);
+ }
-curl_slist_free_all(connect_to);
+ curl_slist_free_all(connect_to);
+}
.fi
.SH AVAILABILITY
Added in 7.49.0
.nf
static CURLcode my_conv_from_ascii_to_ebcdic(char *buffer, size_t length)
{
- char *tempptrin, *tempptrout;
- size_t bytes = length;
- int rc;
- tempptrin = tempptrout = buffer;
- rc = platform_a2e(&tempptrin, &bytes, &tempptrout, &bytes);
- if(rc == PLATFORM_CONV_OK) {
+ int rc = 0;
+
+ /* in-place convert 'buffer' from ASCII to EBCDIC */
+
+ if(rc == 0) {
+ /* success */
return CURLE_OK;
}
else {
}
}
-/* use platform-specific functions for codeset conversions */
-curl_easy_setopt(curl, CURLOPT_CONV_FROM_NETWORK_FUNCTION,
- my_conv_from_ascii_to_ebcdic);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+
+ /* use platform-specific functions for codeset conversions */
+ curl_easy_setopt(curl, CURLOPT_CONV_FROM_NETWORK_FUNCTION,
+ my_conv_from_ascii_to_ebcdic);
+}
.fi
.SH AVAILABILITY
Not available and deprecated since 7.82.0.
.nf
static CURLcode my_conv_from_utf8_to_ebcdic(char *buffer, size_t length)
{
- char *tempptrin, *tempptrout;
- size_t bytes = length;
- int rc;
- tempptrin = tempptrout = buffer;
- rc = platform_u2e(&tempptrin, &bytes, &tempptrout, &bytes);
- if(rc == PLATFORM_CONV_OK) {
+ int rc = 0;
+ /* in-place convert 'buffer' from UTF-8 to EBCDIC */
+ if(rc == 0) {
+ /* success */
return CURLE_OK;
}
else {
}
}
-curl_easy_setopt(curl, CURLOPT_CONV_FROM_UTF8_FUNCTION,
- my_conv_from_utf8_to_ebcdic);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ curl_easy_setopt(curl, CURLOPT_CONV_FROM_UTF8_FUNCTION,
+ my_conv_from_utf8_to_ebcdic);
+}
.fi
.SH AVAILABILITY
Not available and deprecated since 7.82.0.
.nf
static CURLcode my_conv_from_ebcdic_to_ascii(char *buffer, size_t length)
{
- char *tempptrin, *tempptrout;
- size_t bytes = length;
- int rc;
- tempptrin = tempptrout = buffer;
- rc = platform_e2a(&tempptrin, &bytes, &tempptrout, &bytes);
- if(rc == PLATFORM_CONV_OK) {
+ int rc = 0;
+ /* in-place convert 'buffer' from EBCDIC to ASCII */
+ if(rc == 0) {
+ /* success */
return CURLE_OK;
}
else {
}
}
-curl_easy_setopt(curl, CURLOPT_CONV_TO_NETWORK_FUNCTION,
- my_conv_from_ebcdic_to_ascii);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+
+ curl_easy_setopt(curl, CURLOPT_CONV_TO_NETWORK_FUNCTION,
+ my_conv_from_ebcdic_to_ascii);
+}
.fi
.SH AVAILABILITY
Not available and deprecated since 7.82.0.
HTTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- curl_easy_setopt(curl, CURLOPT_COOKIE, "tool=curl; fun=yes;");
+ curl_easy_setopt(curl, CURLOPT_COOKIE, "tool=curl; fun=yes;");
- curl_easy_perform(curl);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
- /* get cookies from an existing file */
- curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "/tmp/cookies.txt");
+ /* get cookies from an existing file */
+ curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "/tmp/cookies.txt");
- ret = curl_easy_perform(curl);
+ res = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH "Cookie file format"
HTTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
- /* export cookies to this file when closing the handle */
- curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "/tmp/cookies.txt");
+ /* export cookies to this file when closing the handle */
+ curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "/tmp/cookies.txt");
- ret = curl_easy_perform(curl);
+ res = curl_easy_perform(curl);
- /* close the handle, write the cookies! */
- curl_easy_cleanup(curl);
+ /* close the handle, write the cookies! */
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
#define SEP "\\t" /* Tab separates the fields */
-char *my_cookie =
- "example.com" /* Hostname */
- SEP "FALSE" /* Include subdomains */
- SEP "/" /* Path */
- SEP "FALSE" /* Secure */
- SEP "0" /* Expiry in epoch time format. 0 == Session */
- SEP "foo" /* Name */
- SEP "bar"; /* Value */
-
-/* my_cookie is imported immediately via CURLOPT_COOKIELIST. */
-curl_easy_setopt(curl, CURLOPT_COOKIELIST, my_cookie);
-
-/* The list of cookies in cookies.txt are not be imported until right
- before a transfer is performed. Cookies in the list that have the same
- hostname, path and name as in my_cookie are skipped. That is because
- libcurl has already imported my_cookie and it's considered a "live"
- cookie. A live cookie is not replaced by one read from a file.
-*/
-curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "cookies.txt"); /* import */
-
-/* Cookies are exported after curl_easy_cleanup is called. The server
- may have added, deleted or modified cookies by then. The cookies that
- were skipped on import are not exported.
-*/
-curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "cookies.txt"); /* export */
-
-curl_easy_perform(curl); /* cookies imported from cookies.txt */
-
-curl_easy_cleanup(curl); /* cookies exported to cookies.txt */
+int main(void)
+{
+ char *my_cookie =
+ "example.com" /* Hostname */
+ SEP "FALSE" /* Include subdomains */
+ SEP "/" /* Path */
+ SEP "FALSE" /* Secure */
+ SEP "0" /* Expiry in epoch time format. 0 == Session */
+ SEP "foo" /* Name */
+ SEP "bar"; /* Value */
+
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ /* my_cookie is imported immediately via CURLOPT_COOKIELIST. */
+ curl_easy_setopt(curl, CURLOPT_COOKIELIST, my_cookie);
+
+ /* The list of cookies in cookies.txt are not be imported until right
+ before a transfer is performed. Cookies in the list that have the same
+ hostname, path and name as in my_cookie are skipped. That is because
+ libcurl has already imported my_cookie and it's considered a "live"
+ cookie. A live cookie is not replaced by one read from a file.
+ */
+ curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "cookies.txt"); /* import */
+
+ /* Cookies are exported after curl_easy_cleanup is called. The server
+ may have added, deleted or modified cookies by then. The cookies that
+ were skipped on import are not exported.
+ */
+ curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "cookies.txt"); /* export */
+
+ curl_easy_perform(curl); /* cookies imported from cookies.txt */
+
+ curl_easy_cleanup(curl); /* cookies exported to cookies.txt */
+ }
+}
.fi
.SH "Cookie file format"
The cookie file format and general cookie concepts in curl are described
HTTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
- /* new "session", do not load session cookies */
- curl_easy_setopt(curl, CURLOPT_COOKIESESSION, 1L);
+ /* new "session", do not load session cookies */
+ curl_easy_setopt(curl, CURLOPT_COOKIESESSION, 1L);
- /* get the (non session) cookies from this file */
- curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "/tmp/cookies.txt");
+ /* get the (non session) cookies from this file */
+ curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "/tmp/cookies.txt");
- ret = curl_easy_perform(curl);
+ res = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP(S)
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- char local_buffer[1024]="data to send";
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ char local_buffer[1024]="data to send";
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* size of the data to copy from the buffer and send in the request */
- curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, 12L);
+ /* size of the data to copy from the buffer and send in the request */
+ curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, 12L);
- /* send data from the local stack */
- curl_easy_setopt(curl, CURLOPT_COPYPOSTFIELDS, local_buffer);
+ /* send data from the local stack */
+ curl_easy_setopt(curl, CURLOPT_COPYPOSTFIELDS, local_buffer);
- curl_easy_perform(curl);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode ret;
- curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/");
- curl_easy_setopt(curl, CURLOPT_CRLF, 1L);
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode ret;
+ curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/");
+ curl_easy_setopt(curl, CURLOPT_CRLF, 1L);
+ ret = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All TLS-based protocols
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_CRLFILE, "/etc/certs/crl.pem");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_CRLFILE, "/etc/certs/crl.pem");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *handle = curl_easy_init();
-CURLU *urlp = curl_url();
-int res = 0;
-if(curl) {
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ CURLU *urlp = curl_url();
+ if(curl) {
+ CURLcode res;
+ CURLUcode ret;
+ ret = curl_url_set(urlp, CURLUPART_URL, "https://example.com", 0);
- res = curl_url_set(urlp, CURLUPART_URL, "https://example.com", 0);
+ curl_easy_setopt(curl, CURLOPT_CURLU, urlp);
- curl_easy_setopt(handle, CURLOPT_CURLU, urlp);
+ res = curl_easy_perform(curl);
- ret = curl_easy_perform(handle);
-
- curl_url_cleanup(urlp);
- curl_easy_cleanup(handle);
+ curl_url_cleanup(urlp);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP, FTP, IMAP, POP3 and SMTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
- /* DELETE the given path */
- curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE");
+ /* DELETE the given path */
+ curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE");
- ret = curl_easy_perform(curl);
+ res = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
+struct data {
+ void *custom;
+};
+
+static int my_trace(CURL *handle, curl_infotype type,
+ char *data, size_t size,
+ void *clientp)
+{
+ struct data *mine = clientp;
+ printf("our ptr: %p\\n", mine->custom);
+
+ /* output debug info */
+}
+
int main(void)
{
CURL *curl;
{
size_t i;
size_t c;
- unsigned int width=0x10;
+ unsigned int width = 0x10;
fprintf(stream, "%s, %10.10ld bytes (0x%8.8lx)\\n",
text, (long)size, (long)size);
- for(i=0; i<size; i+= width) {
+ for(i = 0; i < size; i += width) {
fprintf(stream, "%4.4lx: ", (long)i);
/* show hex to the left */
for(c = 0; c < width; c++) {
- if(i+c < size)
- fprintf(stream, "%02x ", ptr[i+c]);
+ if(i + c < size)
+ fprintf(stream, "%02x ", ptr[i + c]);
else
fputs(" ", stream);
}
/* show data on the right */
- for(c = 0; (c < width) && (i+c < size); c++) {
- char x = (ptr[i+c] >= 0x20 && ptr[i+c] < 0x80) ? ptr[i+c] : '.';
+ for(c = 0; (c < width) && (i + c < size); c++) {
+ char x = (ptr[i + c] >= 0x20 && ptr[i + c] < 0x80) ? ptr[i + c] : '.';
fputc(x, stream);
}
(void)handle; /* prevent compiler warning */
(void)clientp;
- switch (type) {
+ switch(type) {
case CURLINFO_TEXT:
fputs("== Info: ", stderr);
fwrite(data, size, 1, stderr);
All
.SH EXAMPLE
.nf
-curl = curl_easy_init();
-if(curl) {
- /* set a URL without a scheme */
- curl_easy_setopt(curl, CURLOPT_URL, "example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ /* set a URL without a scheme */
+ curl_easy_setopt(curl, CURLOPT_URL, "example.com");
- /* set the default protocol (scheme) for schemeless URLs */
- curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
+ /* set the default protocol (scheme) for schemeless URLs */
+ curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
- /* Perform the request */
- curl_easy_perform(curl);
+ /* Perform the request */
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
FTP, SFTP and POP3
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/dir/");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/dir/");
- /* list only */
- curl_easy_setopt(curl, CURLOPT_DIRLISTONLY, 1L);
+ /* list only */
+ curl_easy_setopt(curl, CURLOPT_DIRLISTONLY, 1L);
- ret = curl_easy_perform(curl);
+ res = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
Several
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- curl_easy_setopt(curl, CURLOPT_DISALLOW_USERNAME_IN_URL, 1L);
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ curl_easy_setopt(curl, CURLOPT_DISALLOW_USERNAME_IN_URL, 1L);
- curl_easy_perform(curl);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
- /* only reuse addresses for a short time */
- curl_easy_setopt(curl, CURLOPT_DNS_CACHE_TIMEOUT, 2L);
+ /* only reuse addresses for a short time */
+ curl_easy_setopt(curl, CURLOPT_DNS_CACHE_TIMEOUT, 2L);
- ret = curl_easy_perform(curl);
+ res = curl_easy_perform(curl);
- /* in this second request, the cache is not be used if more than
- two seconds have passed since the previous name resolve */
- ret = curl_easy_perform(curl);
+ /* in this second request, the cache is not be used if more than
+ two seconds have passed since the previous name resolve */
+ res = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All protocols except file:// - protocols that resolve host names.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
- curl_easy_setopt(curl, CURLOPT_DNS_INTERFACE, "eth0");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
+ curl_easy_setopt(curl, CURLOPT_DNS_INTERFACE, "eth0");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
- curl_easy_setopt(curl, CURLOPT_DNS_LOCAL_IP4, "192.168.0.14");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
+ curl_easy_setopt(curl, CURLOPT_DNS_LOCAL_IP4, "192.168.0.14");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
- curl_easy_setopt(curl, CURLOPT_DNS_LOCAL_IP6, "fe80::a9ff:fe46:b619");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
+ curl_easy_setopt(curl, CURLOPT_DNS_LOCAL_IP6, "fe80::a9ff:fe46:b619");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
- curl_easy_setopt(curl, CURLOPT_DNS_SERVERS, "192.168.1.100:53,192.168.1.101");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
+ curl_easy_setopt(curl, CURLOPT_DNS_SERVERS,
+ "192.168.1.100:53,192.168.1.101");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- curl_easy_setopt(curl, CURLOPT_DNS_SHUFFLE_ADDRESSES, 1L);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ curl_easy_setopt(curl, CURLOPT_DNS_SHUFFLE_ADDRESSES, 1L);
- curl_easy_perform(curl);
+ curl_easy_perform(curl);
- /* always cleanup */
- curl_easy_cleanup(curl);
+ /* always cleanup */
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode ret;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- /* switch off the use of a global, thread unsafe, cache */
- curl_easy_setopt(curl, CURLOPT_DNS_USE_GLOBAL_CACHE, 0L);
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode ret;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ /* switch off the use of a global, thread unsafe, cache */
+ curl_easy_setopt(curl, CURLOPT_DNS_USE_GLOBAL_CACHE, 0L);
+ ret = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
+
.fi
.SH AVAILABILITY
Deprecated since 7.11.1. Function removed in 7.62.0.
DoH
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- curl_easy_setopt(curl, CURLOPT_DOH_URL, "https://cloudflare-dns.com/dns-query");
+ curl_easy_setopt(curl, CURLOPT_DOH_URL,
+ "https://cloudflare-dns.com/dns-query");
- /* Disable host name verification of the DoH server */
- curl_easy_setopt(curl, CURLOPT_DOH_SSL_VERIFYHOST, 0L);
+ /* Disable host name verification of the DoH server */
+ curl_easy_setopt(curl, CURLOPT_DOH_SSL_VERIFYHOST, 0L);
- curl_easy_perform(curl);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
DoH
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- curl_easy_setopt(curl, CURLOPT_DOH_URL, "https://cloudflare-dns.com/dns-query");
+ curl_easy_setopt(curl, CURLOPT_DOH_URL,
+ "https://cloudflare-dns.com/dns-query");
- /* Disable certificate verification of the DoH server */
- curl_easy_setopt(curl, CURLOPT_DOH_SSL_VERIFYPEER, 0L);
+ /* Disable certificate verification of the DoH server */
+ curl_easy_setopt(curl, CURLOPT_DOH_SSL_VERIFYPEER, 0L);
- curl_easy_perform(curl);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
DoH
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- curl_easy_setopt(curl, CURLOPT_DOH_URL, "https://cloudflare-dns.com/dns-query");
+ curl_easy_setopt(curl, CURLOPT_DOH_URL,
+ "https://cloudflare-dns.com/dns-query");
- /* Ask for OCSP stapling when verifying the DoH server */
- curl_easy_setopt(curl, CURLOPT_DOH_SSL_VERIFYSTATUS, 1L);
+ /* Ask for OCSP stapling when verifying the DoH server */
+ curl_easy_setopt(curl, CURLOPT_DOH_SSL_VERIFYSTATUS, 1L);
- curl_easy_perform(curl);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- curl_easy_setopt(curl, CURLOPT_DOH_URL, "https://dns.example.com");
- curl_easy_perform(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ curl_easy_setopt(curl, CURLOPT_DOH_URL, "https://dns.example.com");
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
All TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_EGDSOCKET, "/var/egd.socket");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_EGDSOCKET, "/var/egd.socket");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-curl = curl_easy_init();
-if(curl) {
- CURLcode res;
- char errbuf[CURL_ERROR_SIZE];
+#include <string.h> /* for strlen() */
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ char errbuf[CURL_ERROR_SIZE];
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* provide a buffer to store errors in */
- curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf);
+ /* provide a buffer to store errors in */
+ curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf);
- /* set the error buffer as empty before performing a request */
- errbuf[0] = 0;
+ /* set the error buffer as empty before performing a request */
+ errbuf[0] = 0;
- /* perform the request */
- res = curl_easy_perform(curl);
+ /* perform the request */
+ res = curl_easy_perform(curl);
- /* if the request did not complete correctly, show the error
- information. if no detailed error information was written to errbuf
- show the more generic information from curl_easy_strerror instead.
- */
- if(res != CURLE_OK) {
- size_t len = strlen(errbuf);
- fprintf(stderr, "\\nlibcurl: (%d) ", res);
- if(len)
- fprintf(stderr, "%s%s", errbuf,
- ((errbuf[len - 1] != '\\n') ? "\\n" : ""));
- else
- fprintf(stderr, "%s\\n", curl_easy_strerror(res));
+ /* if the request did not complete correctly, show the error
+ information. if no detailed error information was written to errbuf
+ show the more generic information from curl_easy_strerror instead.
+ */
+ if(res != CURLE_OK) {
+ size_t len = strlen(errbuf);
+ fprintf(stderr, "\\nlibcurl: (%d) ", res);
+ if(len)
+ fprintf(stderr, "%s%s", errbuf,
+ ((errbuf[len - 1] != '\\n') ? "\\n" : ""));
+ else
+ fprintf(stderr, "%s\\n", curl_easy_strerror(res));
+ }
}
}
.fi
HTTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ 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);
+ /* wait 3 seconds for 100-continue */
+ curl_easy_setopt(curl, CURLOPT_EXPECT_100_TIMEOUT_MS, 3000L);
- curl_easy_perform(curl);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode ret;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
- ret = curl_easy_perform(curl);
- if(ret == CURLE_HTTP_RETURNED_ERROR) {
- /* an HTTP response error problem */
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode ret;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
+ ret = curl_easy_perform(curl);
+ if(ret == CURLE_HTTP_RETURNED_ERROR) {
+ /* an HTTP response error problem */
+ }
}
}
.fi
HTTP(S), FTP(S), SFTP, FILE, SMB(S)
.SH EXAMPLE
.nf
-curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, url);
- /* Ask for filetime */
- curl_easy_setopt(curl, CURLOPT_FILETIME, 1L);
- res = curl_easy_perform(curl);
- if(CURLE_OK == res) {
- res = curl_easy_getinfo(curl, CURLINFO_FILETIME, &filetime);
- if((CURLE_OK == res) && (filetime >= 0)) {
- time_t file_time = (time_t)filetime;
- printf("filetime %s: %s", filename, ctime(&file_time));
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/path.html");
+ /* Ask for filetime */
+ curl_easy_setopt(curl, CURLOPT_FILETIME, 1L);
+ res = curl_easy_perform(curl);
+ if(CURLE_OK == res) {
+ long filetime;
+ res = curl_easy_getinfo(curl, CURLINFO_FILETIME, &filetime);
+ if((CURLE_OK == res) && (filetime >= 0)) {
+ time_t file_time = (time_t)filetime;
+ printf("filetime: %s", ctime(&file_time));
+ }
}
+ /* always cleanup */
+ curl_easy_cleanup(curl);
}
- /* always cleanup */
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
FTP
.SH EXAMPLE
.nf
+extern int string_match(const char *s1, const char *s2);
+
+struct local_stuff {
+ void *custom;
+};
+
static int my_fnmatch(void *clientp,
const char *pattern, const char *string)
{
- struct local_stuff *data = (struct local_stuff *)clientp;
+ struct local_stuff *my = clientp;
+ printf("my ptr: %p\\n", my->custom);
+
if(string_match(pattern, string))
return CURL_FNMATCHFUNC_MATCH;
else
return CURL_FNMATCHFUNC_NOMATCH;
}
+int main(void)
{
struct local_stuff local_data;
- 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 *curl = curl_easy_init();
+ if(curl) {
+ 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);
+ }
}
.fi
.SH AVAILABILITY
FTP
.SH EXAMPLE
.nf
+extern int string_match(const char *s1, const char *s2);
+
+struct local_stuff {
+ void *custom;
+};
static int my_fnmatch(void *clientp,
const char *pattern, const char *string)
{
- struct local_stuff *data = (struct local_stuff *)clientp;
+ struct local_stuff *data = clientp;
+ printf("my pointer: %p\\n", data->custom);
if(string_match(pattern, string))
return CURL_FNMATCHFUNC_MATCH;
else
return CURL_FNMATCHFUNC_NOMATCH;
}
+int main(void)
{
struct local_stuff local_data;
- 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 *curl = curl_easy_init();
+ if(curl) {
+ 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);
+ }
}
.fi
.SH AVAILABILITY
HTTP(S)
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ 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);
+ /* example.com is redirected, so we tell libcurl to follow redirection */
+ curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
- curl_easy_perform(curl);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
Most
.SH EXAMPLE
.nf
+int main(void)
{
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_FORBID_REUSE, 1L);
- curl_easy_perform(curl);
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_FORBID_REUSE, 1L);
+ curl_easy_perform(curl);
- /* this second transfer may not reuse the same connection */
- curl_easy_perform(curl);
+ /* this second transfer may not reuse the same connection */
+ curl_easy_perform(curl);
+
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
Most
.SH EXAMPLE
.nf
+int main(void)
{
- 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);
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ 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);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
FTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/old-server/file.txt");
- curl_easy_setopt(curl, CURLOPT_FTPPORT, "-");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL,
+ "ftp://example.com/old-server/file.txt");
+ curl_easy_setopt(curl, CURLOPT_FTPPORT, "-");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
FTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/file.txt");
- curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_TRY);
- /* funny server, ask for SSL before TLS */
- curl_easy_setopt(curl, CURLOPT_FTPSSLAUTH, (long)CURLFTPAUTH_SSL);
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/file.txt");
+ curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_TRY);
+ /* funny server, ask for SSL before TLS */
+ curl_easy_setopt(curl, CURLOPT_FTPSSLAUTH, (long)CURLFTPAUTH_SSL);
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
FTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/foo.bin");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/foo.bin");
- curl_easy_setopt(curl, CURLOPT_FTP_ACCOUNT, "human-resources");
+ curl_easy_setopt(curl, CURLOPT_FTP_ACCOUNT, "human-resources");
- ret = curl_easy_perform(curl);
+ res = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
FTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/foo.bin");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/foo.bin");
+ curl_easy_setopt(curl, CURLOPT_FTP_ALTERNATIVE_TO_USER, "two users");
+ res = curl_easy_perform(curl);
- curl_easy_setopt(curl, CURLOPT_FTP_ALTERNATIVE_TO_USER, "two users");
-
- ret = curl_easy_perform(curl);
-
- curl_easy_cleanup(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
FTP and SFTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/non-existing/new.txt");
- curl_easy_setopt(curl, CURLOPT_FTP_CREATE_MISSING_DIRS,
- (long)CURLFTP_CREATE_DIR_RETRY);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL,
+ "ftp://example.com/non-existing/new.txt");
+ curl_easy_setopt(curl, CURLOPT_FTP_CREATE_MISSING_DIRS,
+ (long)CURLFTP_CREATE_DIR_RETRY);
- ret = curl_easy_perform(curl);
+ res = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
FTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/1/2/3/4/new.txt");
- curl_easy_setopt(curl, CURLOPT_FTP_FILEMETHOD,
- (long)CURLFTPMETHOD_SINGLECWD);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/1/2/3/4/new.txt");
+ curl_easy_setopt(curl, CURLOPT_FTP_FILEMETHOD,
+ (long)CURLFTPMETHOD_SINGLECWD);
- ret = curl_easy_perform(curl);
+ res = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
FTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/file.txt");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/file.txt");
- /* please ignore the IP in the PASV response */
- curl_easy_setopt(curl, CURLOPT_FTP_SKIP_PASV_IP, 1L);
- ret = curl_easy_perform(curl);
+ /* please ignore the IP in the PASV response */
+ curl_easy_setopt(curl, CURLOPT_FTP_SKIP_PASV_IP, 1L);
+ res = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
FTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/file.txt");
- curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_CONTROL);
- /* go back to clear-text FTP after authenticating */
- curl_easy_setopt(curl, CURLOPT_FTP_SSL_CCC, (long)CURLFTPSSL_CCC_ACTIVE);
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/file.txt");
+ curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_CONTROL);
+ /* go back to clear-text FTP after authenticating */
+ curl_easy_setopt(curl, CURLOPT_FTP_SSL_CCC, (long)CURLFTPSSL_CCC_ACTIVE);
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
.SH PROTOCOLS
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/file.txt");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/file.txt");
- /* contact us back, aka "active" FTP */
- curl_easy_setopt(curl, CURLOPT_FTPPORT, "-");
+ /* contact us back, aka "active" FTP */
+ curl_easy_setopt(curl, CURLOPT_FTPPORT, "-");
- /* FTP the way the neanderthals did it */
- curl_easy_setopt(curl, CURLOPT_FTP_USE_EPRT, 0L);
+ /* FTP the way the neanderthals did it */
+ curl_easy_setopt(curl, CURLOPT_FTP_USE_EPRT, 0L);
- ret = curl_easy_perform(curl);
+ res = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
FTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/old-server/file.txt");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL,
+ "ftp://example.com/old-server/file.txt");
- /* let's shut off this modern feature */
- curl_easy_setopt(curl, CURLOPT_FTP_USE_EPSV, 0L);
+ /* let's shut off this modern feature */
+ curl_easy_setopt(curl, CURLOPT_FTP_USE_EPSV, 0L);
- ret = curl_easy_perform(curl);
+ res = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
FTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/old-server/file.txt");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL,
+ "ftp://example.com/old-server/file.txt");
- /* a drftpd server, do it! */
- curl_easy_setopt(curl, CURLOPT_FTP_USE_PRET, 1L);
+ /* a drftpd server, do it! */
+ curl_easy_setopt(curl, CURLOPT_FTP_USE_PRET, 1L);
- ret = curl_easy_perform(curl);
+ res = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode ret;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- /* delegate if okayed by policy */
- curl_easy_setopt(curl, CURLOPT_GSSAPI_DELEGATION,
- (long)CURLGSSAPI_DELEGATION_POLICY_FLAG);
- ret = curl_easy_perform(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode ret;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ /* delegate if okayed by policy */
+ curl_easy_setopt(curl, CURLOPT_GSSAPI_DELEGATION,
+ (long)CURLGSSAPI_DELEGATION_POLICY_FLAG);
+ ret = curl_easy_perform(curl);
+ }
}
.fi
All except FILE
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- curl_easy_setopt(curl, CURLOPT_HAPPY_EYEBALLS_TIMEOUT_MS, 300L);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ curl_easy_setopt(curl, CURLOPT_HAPPY_EYEBALLS_TIMEOUT_MS, 300L);
- curl_easy_perform(curl);
+ curl_easy_perform(curl);
- /* always cleanup */
- curl_easy_cleanup(curl);
+ /* always cleanup */
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode ret;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_HAPROXYPROTOCOL, 1L);
- ret = curl_easy_perform(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode ret;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_HAPROXYPROTOCOL, 1L);
+ ret = curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP, HAProxy PROTOCOL
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode ret;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_HAPROXY_CLIENT_IP, "1.1.1.1");
- ret = curl_easy_perform(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode ret;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_HAPROXY_CLIENT_IP, "1.1.1.1");
+ ret = curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
Most
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- curl_easy_setopt(curl, CURLOPT_HEADER, 1L);
+ curl_easy_setopt(curl, CURLOPT_HEADER, 1L);
- curl_easy_perform(curl);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
static size_t header_callback(char *buffer, size_t size,
size_t nitems, void *userdata)
{
- struct my_info *i = (struct my_info *)userdata;
-
+ struct my_info *i = userdata;
+ printf("shoe size: %d\\n", i->shoesize);
/* now this callback can access the my_info struct */
return nitems * size;
}
-CURL *curl = curl_easy_init();
-if(curl) {
- struct my_info my = { 10, "the cookies are in the cupboard" };
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ struct my_info my = { 10, "the cookies are in the cupboard" };
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, header_callback);
+ curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, header_callback);
- /* pass in custom data to the callback */
- curl_easy_setopt(curl, CURLOPT_HEADERDATA, &my);
+ /* pass in custom data to the callback */
+ curl_easy_setopt(curl, CURLOPT_HEADERDATA, &my);
- curl_easy_perform(curl);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
return nitems * size;
}
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, header_callback);
+ curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, header_callback);
- curl_easy_perform(curl);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode ret;
- struct curl_slist *list;
- list = curl_slist_append(NULL, "Shoesize: 10");
- list = curl_slist_append(list, "Accept:");
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_PROXY, "http://localhost:8080");
- curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode ret;
+ struct curl_slist *list;
+ list = curl_slist_append(NULL, "Shoesize: 10");
+ list = curl_slist_append(list, "Accept:");
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_PROXY, "http://localhost:8080");
+ curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);
- /* HTTPS over a proxy makes a separate CONNECT to the proxy, so tell
- libcurl to not send the custom headers to the proxy. Keep them
- separate! */
- curl_easy_setopt(curl, CURLOPT_HEADEROPT, CURLHEADER_SEPARATE);
- ret = curl_easy_perform(curl);
- curl_slist_free_all(list);
- curl_easy_cleanup(curl);
+ /* HTTPS over a proxy makes a separate CONNECT to the proxy, so tell
+ libcurl to not send the custom headers to the proxy. Keep them
+ separate! */
+ curl_easy_setopt(curl, CURLOPT_HEADEROPT, CURLHEADER_SEPARATE);
+ ret = curl_easy_perform(curl);
+ curl_slist_free_all(list);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTPS and HTTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_HSTS, "/home/user/.hsts-cache");
- curl_easy_perform(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_HSTS, "/home/user/.hsts-cache");
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
This feature is only used for HTTP(S) transfer.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-struct MyData this;
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
+struct MyData {
+ void *custom;
+};
- /* pass pointer that gets passed in to the
- CURLOPT_HSTSREADFUNCTION callback */
- curl_easy_setopt(curl, CURLOPT_HSTSREADDATA, &this);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ struct MyData this;
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
- curl_easy_perform(curl);
+ /* pass pointer that gets passed in to the
+ CURLOPT_HSTSREADFUNCTION callback */
+ curl_easy_setopt(curl, CURLOPT_HSTSREADDATA, &this);
+
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
This feature is only used for HTTP(S) transfer.
.SH EXAMPLE
.nf
+struct priv {
+ 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)
{
- /* set HSTS read callback */
- curl_easy_setopt(curl, CURLOPT_HSTSREADFUNCTION, hstsread);
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ struct priv my_stuff;
+ CURLcode res;
+
+ /* set HSTS read callback */
+ curl_easy_setopt(curl, CURLOPT_HSTSREADFUNCTION, hsts_cb);
- /* pass in suitable argument to the callback */
- curl_easy_setopt(curl, CURLOPT_HSTSREADDATA, &hstspreload[0]);
+ /* pass in suitable argument to the callback */
+ curl_easy_setopt(curl, CURLOPT_HSTSREADDATA, &my_stuff);
- result = curl_easy_perform(curl);
+ res = curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
This feature is only used for HTTP(S) transfer.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-struct MyData this;
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
+struct MyData {
+ void *custom;
+};
- /* pass pointer that gets passed in to the
- CURLOPT_HSTSWRITEFUNCTION callback */
- curl_easy_setopt(curl, CURLOPT_HSTSWRITEDATA, &this);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ struct MyData this;
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
- curl_easy_perform(curl);
+ /* pass pointer that gets passed in to the
+ CURLOPT_HSTSWRITEFUNCTION callback */
+ curl_easy_setopt(curl, CURLOPT_HSTSWRITEDATA, &this);
+
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
This feature is only used for HTTP(S) transfer.
.SH EXAMPLE
.nf
+struct priv {
+ void *custom;
+};
+
+static CURLSTScode hswr_cb(CURL *easy, struct curl_hstsentry *sts,
+ struct curl_index *count, void *clientp)
+{
+ /* save the passed in HSTS data somewhere */
+ return CURLSTS_OK;
+}
+
+int main(void)
{
- /* set HSTS read callback */
- curl_easy_setopt(curl, CURLOPT_HSTSWRITEFUNCTION, hstswrite);
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ struct priv my_stuff;
+ CURLcode res;
+
+ /* set HSTS read callback */
+ curl_easy_setopt(curl, CURLOPT_HSTSWRITEFUNCTION, hswr_cb);
- /* pass in suitable argument to the callback */
- curl_easy_setopt(curl, CURLOPT_HSTSWRITEDATA, &hstspreload[0]);
+ /* pass in suitable argument to the callback */
+ curl_easy_setopt(curl, CURLOPT_HSTSWRITEDATA, &my_stuff);
- result = curl_easy_perform(curl);
+ res = curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTPS and HTTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_HSTS_CTRL, (long)CURLHSTS_ENABLE);
- curl_easy_perform(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_HSTS_CTRL, (long)CURLHSTS_ENABLE);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode ret;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_HTTP09_ALLOWED, 1L);
- ret = curl_easy_perform(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode ret;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_HTTP09_ALLOWED, 1L);
+ ret = curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- struct curl_slist *list;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ struct curl_slist *list;
+ 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");
+ 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);
- curl_slist_free_all(list); /* free the list again */
+ curl_easy_setopt(curl, CURLOPT_HTTP200ALIASES, list);
+ curl_easy_perform(curl);
+ curl_slist_free_all(list); /* free the list again */
+ }
}
.fi
.SH AVAILABILITY
HTTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode ret;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- /* allow whatever auth the server speaks */
- curl_easy_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_ANY);
- curl_easy_setopt(curl, CURLOPT_USERPWD, "james:bond");
- ret = curl_easy_perform(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode ret;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ /* allow whatever auth the server speaks */
+ curl_easy_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_ANY);
+ curl_easy_setopt(curl, CURLOPT_USERPWD, "james:bond");
+ ret = curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP(S)
.SH EXAMPLE
.nf
-curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* use a GET to fetch this */
- curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
+ /* use a GET to fetch this */
+ curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
- /* Perform the request */
- curl_easy_perform(curl);
+ /* Perform the request */
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP, IMAP and SMTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
+int main(void)
+{
+ CURL *curl = curl_easy_init();
-struct curl_slist *list = NULL;
+ struct curl_slist *list = NULL;
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- list = curl_slist_append(list, "Shoesize: 10");
- list = curl_slist_append(list, "Accept:");
+ list = curl_slist_append(list, "Shoesize: 10");
+ list = curl_slist_append(list, "Accept:");
- curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);
+ curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);
- curl_easy_perform(curl);
+ curl_easy_perform(curl);
- curl_slist_free_all(list); /* free the list */
+ curl_slist_free_all(list); /* free the list */
+ }
}
.fi
HTTP
.SH EXAMPLE
.nf
-/* Fill in the file upload field. This makes libcurl load data from
- the given file name when curl_easy_perform() is called. */
-curl_formadd(&formpost,
- &lastptr,
- CURLFORM_COPYNAME, "sendfile",
- CURLFORM_FILE, "postit2.c",
- CURLFORM_END);
+int main(void)
+{
+ struct curl_httppost *formpost;
+ struct curl_httppost *lastptr;
-/* Fill in the filename field */
-curl_formadd(&formpost,
- &lastptr,
- CURLFORM_COPYNAME, "filename",
- CURLFORM_COPYCONTENTS, "postit2.c",
- CURLFORM_END);
+ /* Fill in the file upload field. This makes libcurl load data from
+ the given file name when curl_easy_perform() is called. */
+ curl_formadd(&formpost,
+ &lastptr,
+ CURLFORM_COPYNAME, "sendfile",
+ CURLFORM_FILE, "postit2.c",
+ CURLFORM_END);
-/* Fill in the submit field too, even if this is rarely needed */
-curl_formadd(&formpost,
- &lastptr,
- CURLFORM_COPYNAME, "submit",
- CURLFORM_COPYCONTENTS, "send",
- CURLFORM_END);
+ /* Fill in the filename field */
+ curl_formadd(&formpost,
+ &lastptr,
+ CURLFORM_COPYNAME, "filename",
+ CURLFORM_COPYCONTENTS, "postit2.c",
+ CURLFORM_END);
+
+ /* Fill in the submit field too, even if this is rarely needed */
+ curl_formadd(&formpost,
+ &lastptr,
+ CURLFORM_COPYNAME, "submit",
+ CURLFORM_COPYCONTENTS, "send",
+ CURLFORM_END);
+
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
+ curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
+ curl_formfree(formpost);
+}
.fi
.SH AVAILABILITY
As long as HTTP is enabled. Deprecated in 7.56.0.
All network protocols
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- 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);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ 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);
+ }
}
.fi
.SH AVAILABILITY
HTTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode ret;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_HTTP_CONTENT_DECODING, 0L);
- ret = curl_easy_perform(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode ret;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_HTTP_CONTENT_DECODING, 0L);
+ ret = curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode ret;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_HTTP_TRANSFER_DECODING, 0L);
- ret = curl_easy_perform(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode ret;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_HTTP_TRANSFER_DECODING, 0L);
+ ret = curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode ret;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_HTTP_VERSION,
- (long)CURL_HTTP_VERSION_2TLS);
- ret = curl_easy_perform(curl);
- if(ret == CURLE_HTTP_RETURNED_ERROR) {
- /* an HTTP response error problem */
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode ret;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_HTTP_VERSION,
+ (long)CURL_HTTP_VERSION_2TLS);
+ ret = curl_easy_perform(curl);
+ if(ret == CURLE_HTTP_RETURNED_ERROR) {
+ /* an HTTP response error problem */
+ }
}
}
.fi
HTTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ 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);
+ /* we know the server is silly, ignore content-length */
+ curl_easy_setopt(curl, CURLOPT_IGNORE_CONTENT_LENGTH, 1L);
- curl_easy_perform(curl);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
Many
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- long uploadsize = FILE_SIZE;
- curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/destination.tar.gz");
+#define FILE_SIZE 12345L
- curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ long uploadsize = FILE_SIZE;
- curl_easy_setopt(curl, CURLOPT_INFILESIZE, uploadsize);
+ curl_easy_setopt(curl, CURLOPT_URL,
+ "ftp://example.com/destination.tar.gz");
- curl_easy_perform(curl);
+ curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
+
+ curl_easy_setopt(curl, CURLOPT_INFILESIZE, uploadsize);
+
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
Many
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_off_t uploadsize = FILE_SIZE;
+#define FILE_SIZE 123456
- curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/destination.tar.gz");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_off_t uploadsize = FILE_SIZE;
- curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
+ curl_easy_setopt(curl, CURLOPT_URL,
+ "ftp://example.com/destination.tar.gz");
- curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, uploadsize);
+ curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
- curl_easy_perform(curl);
+ curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, uploadsize);
+
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
- curl_easy_setopt(curl, CURLOPT_INTERFACE, "eth0");
+ curl_easy_setopt(curl, CURLOPT_INTERFACE, "eth0");
- ret = curl_easy_perform(curl);
+ res = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
RTSP
.SH EXAMPLE
.nf
-static size_t rtp_write(void *ptr, size_t size, size_t nmemb, void *user)
+struct local {
+ void *custom;
+};
+static size_t rtp_write(void *ptr, size_t size, size_t nmemb, void *userp)
{
- struct local *l = (struct local *)user;
+ struct local *l = userp;
+ printf("my pointer: %p\\n", l->custom);
/* take care of the packet in 'ptr', then return... */
return size * nmemb;
}
+
+int main(void)
{
struct local rtp_data;
- curl_easy_setopt(curl, CURLOPT_INTERLEAVEFUNCTION, rtp_write);
- curl_easy_setopt(curl, CURLOPT_INTERLEAVEDATA, &rtp_data);
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_INTERLEAVEFUNCTION, rtp_write);
+ curl_easy_setopt(curl, CURLOPT_INTERLEAVEDATA, &rtp_data);
+
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
RTSP
.SH EXAMPLE
.nf
-static size_t rtp_write(void *ptr, size_t size, size_t nmemb, void *user)
+struct local {
+ void *custom;
+};
+
+static size_t rtp_write(void *ptr, size_t size, size_t nmemb, void *userp)
{
- struct local *l = (struct local *)user;
+ struct local *l = userp;
+ printf("our ptr: %p\\n", l->custom);
/* take care of the packet in 'ptr', then return... */
return size * nmemb;
}
+
+int main(void)
{
struct local rtp_data;
- curl_easy_setopt(curl, CURLOPT_INTERLEAVEFUNCTION, rtp_write);
- curl_easy_setopt(curl, CURLOPT_INTERLEAVEDATA, &rtp_data);
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_INTERLEAVEFUNCTION, rtp_write);
+ curl_easy_setopt(curl, CURLOPT_INTERLEAVEDATA, &rtp_data);
+ }
}
.fi
.SH AVAILABILITY
Used with HTTP
.SH EXAMPLE
.nf
+#include <unistd.h> /* for lseek */
+
+struct data {
+ int fd; /* our file descriptor */
+};
+
static curlioerr ioctl_callback(CURL *handle, int cmd, void *clientp)
{
struct data *io = (struct data *)clientp;
if(cmd == CURLIOCMD_RESTARTREAD) {
- lseek(fd, 0, SEEK_SET);
- current_offset = 0;
+ lseek(io->fd, 0, SEEK_SET);
return CURLIOE_OK;
}
return CURLIOE_UNKNOWNCMD;
}
+int main(void)
{
struct data ioctl_data;
- curl_easy_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctl_callback);
- curl_easy_setopt(curl, CURLOPT_IOCTLDATA, &ioctl_data);
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctl_callback);
+ curl_easy_setopt(curl, CURLOPT_IOCTLDATA, &ioctl_data);
+ }
}
.fi
.SH AVAILABILITY
Used with HTTP
.SH EXAMPLE
.nf
+#include <unistd.h> /* for lseek */
+
+struct data {
+ int fd; /* our file descriptor */
+};
+
static curlioerr ioctl_callback(CURL *handle, int cmd, void *clientp)
{
struct data *io = (struct data *)clientp;
if(cmd == CURLIOCMD_RESTARTREAD) {
- lseek(fd, 0, SEEK_SET);
- current_offset = 0;
+ lseek(io->fd, 0, SEEK_SET);
return CURLIOE_OK;
}
return CURLIOE_UNKNOWNCMD;
}
+int main(void)
{
struct data ioctl_data;
- curl_easy_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctl_callback);
- curl_easy_setopt(curl, CURLOPT_IOCTLDATA, &ioctl_data);
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctl_callback);
+ curl_easy_setopt(curl, CURLOPT_IOCTLDATA, &ioctl_data);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
- /* of all addresses example.com resolves to, only IPv6 ones are used */
- curl_easy_setopt(curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V6);
+ /* of all addresses example.com resolves to, only IPv6 ones are used */
+ curl_easy_setopt(curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V6);
- ret = curl_easy_perform(curl);
+ res = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
-
.SH AVAILABILITY
Always
.SH RETURN VALUE
All TLS-based protocols
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_ISSUERCERT, "/etc/certs/cacert.pem");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_ISSUERCERT, "/etc/certs/cacert.pem");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All TLS-based protocols
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- struct curl_blob blob;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- blob.data = certificateData;
- blob.len = filesize;
- blob.flags = CURL_BLOB_COPY;
- curl_easy_setopt(curl, CURLOPT_ISSUERCERT_BLOB, &blob);
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+
+extern char *certificateData;
+extern size_t filesize;
+
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ struct curl_blob blob;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ blob.data = certificateData;
+ blob.len = filesize;
+ blob.flags = CURL_BLOB_COPY;
+ curl_easy_setopt(curl, CURLOPT_ISSUERCERT_BLOB, &blob);
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode ret;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "sending data");
- curl_easy_setopt(curl, CURLOPT_KEEP_SENDING_ON_ERROR, 1L);
- ret = curl_easy_perform(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode ret;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "sending data");
+ curl_easy_setopt(curl, CURLOPT_KEEP_SENDING_ON_ERROR, 1L);
+ ret = curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
All TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
- curl_easy_setopt(curl, CURLOPT_SSLCERT, "client.pem");
- curl_easy_setopt(curl, CURLOPT_SSLKEY, "key.pem");
- curl_easy_setopt(curl, CURLOPT_KEYPASSWD, "superman");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
+ curl_easy_setopt(curl, CURLOPT_SSLCERT, "client.pem");
+ curl_easy_setopt(curl, CURLOPT_SSLKEY, "key.pem");
+ curl_easy_setopt(curl, CURLOPT_KEYPASSWD, "superman");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
FTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/foo.bin");
- curl_easy_setopt(curl, CURLOPT_KRBLEVEL, "private");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/foo.bin");
+ curl_easy_setopt(curl, CURLOPT_KRBLEVEL, "private");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
- curl_easy_setopt(curl, CURLOPT_LOCALPORT, 49152L);
- /* and try 20 more ports following that */
- curl_easy_setopt(curl, CURLOPT_LOCALPORTRANGE, 20L);
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
+ curl_easy_setopt(curl, CURLOPT_LOCALPORT, 49152L);
+ /* and try 20 more ports following that */
+ curl_easy_setopt(curl, CURLOPT_LOCALPORTRANGE, 20L);
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
- curl_easy_setopt(curl, CURLOPT_LOCALPORT, 49152L);
- /* and try 20 more ports following that */
- curl_easy_setopt(curl, CURLOPT_LOCALPORTRANGE, 20L);
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
+ curl_easy_setopt(curl, CURLOPT_LOCALPORT, 49152L);
+ /* and try 20 more ports following that */
+ curl_easy_setopt(curl, CURLOPT_LOCALPORTRANGE, 20L);
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
Only IMAP, LDAP, POP3 and SMTP support login options.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "smtp://example.com/");
- curl_easy_setopt(curl, CURLOPT_LOGIN_OPTIONS, "AUTH=*");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "smtp://example.com/");
+ curl_easy_setopt(curl, CURLOPT_LOGIN_OPTIONS, "AUTH=*");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, url);
- /* abort if slower than 30 bytes/sec during 60 seconds */
- curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 60L);
- curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 30L);
- res = curl_easy_perform(curl);
- if(CURLE_OPERATION_TIMEDOUT == res) {
- printf("Timeout!\\n");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ /* abort if slower than 30 bytes/sec during 60 seconds */
+ curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 60L);
+ curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 30L);
+ res = curl_easy_perform(curl);
+ if(CURLE_OPERATION_TIMEDOUT == res) {
+ printf("Timeout!\\n");
+ }
+ /* always cleanup */
+ curl_easy_cleanup(curl);
}
- /* always cleanup */
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, url);
- /* abort if slower than 30 bytes/sec during 60 seconds */
- curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 60L);
- curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 30L);
- res = curl_easy_perform(curl);
- if(CURLE_OPERATION_TIMEDOUT == res) {
- printf("Timeout!\\n");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ /* abort if slower than 30 bytes/sec during 60 seconds */
+ curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 60L);
+ curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 30L);
+ res = curl_easy_perform(curl);
+ if(CURLE_OPERATION_TIMEDOUT == res) {
+ printf("Timeout!\\n");
+ }
+ /* always cleanup */
+ curl_easy_cleanup(curl);
}
- /* always cleanup */
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
SMTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "smtp://example.com/");
- curl_easy_setopt(curl, CURLOPT_MAIL_AUTH, "<secret@cave>");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "smtp://example.com/");
+ curl_easy_setopt(curl, CURLOPT_MAIL_AUTH, "<secret@cave>");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
SMTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "smtp://example.com/");
- curl_easy_setopt(curl, CURLOPT_MAIL_FROM, "president@example.com");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "smtp://example.com/");
+ curl_easy_setopt(curl, CURLOPT_MAIL_FROM, "president@example.com");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
SMTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- struct curl_slist *list;
- list = curl_slist_append(NULL, "root@localhost");
- list = curl_slist_append(list, "person@example.com");
- curl_easy_setopt(curl, CURLOPT_URL, "smtp://example.com/");
- curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, list);
- ret = curl_easy_perform(curl);
- curl_slist_free_all(list);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ struct curl_slist *list;
+ list = curl_slist_append(NULL, "root@localhost");
+ list = curl_slist_append(list, "person@example.com");
+ curl_easy_setopt(curl, CURLOPT_URL, "smtp://example.com/");
+ curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, list);
+ res = curl_easy_perform(curl);
+ curl_slist_free_all(list);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
SMTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- struct curl_slist *list;
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ struct curl_slist *list;
+ CURLcode res;
- /* Adding one valid and one invalid email address */
- list = curl_slist_append(NULL, "person@example.com");
- list = curl_slist_append(list, "invalidemailaddress");
+ /* Adding one valid and one invalid email address */
+ list = curl_slist_append(NULL, "person@example.com");
+ list = curl_slist_append(list, "invalidemailaddress");
- curl_easy_setopt(curl, CURLOPT_URL, "smtp://example.com/");
- curl_easy_setopt(curl, CURLOPT_MAIL_RCPT_ALLOWFAILS, 1L);
+ curl_easy_setopt(curl, CURLOPT_URL, "smtp://example.com/");
+ curl_easy_setopt(curl, CURLOPT_MAIL_RCPT_ALLOWFAILS, 1L);
- ret = curl_easy_perform(curl);
- curl_slist_free_all(list);
- curl_easy_cleanup(curl);
+ res = curl_easy_perform(curl);
+ curl_slist_free_all(list);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* only allow 30 seconds idle time */
- curl_easy_setopt(curl, CURLOPT_MAXAGE_CONN, 30L);
+ /* only allow 30 seconds idle time */
+ curl_easy_setopt(curl, CURLOPT_MAXAGE_CONN, 30L);
- curl_easy_perform(curl);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
Most
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode ret;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- /* limit the connection cache for this handle to no more than 3 */
- curl_easy_setopt(curl, CURLOPT_MAXCONNECTS, 3L);
- ret = curl_easy_perform(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode ret;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ /* limit the connection cache for this handle to no more than 3 */
+ curl_easy_setopt(curl, CURLOPT_MAXCONNECTS, 3L);
+ ret = curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
FTP, HTTP and MQTT
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode ret;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- /* refuse to download if larger than 1000 bytes! */
- curl_easy_setopt(curl, CURLOPT_MAXFILESIZE, 1000L);
- ret = curl_easy_perform(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode ret;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ /* refuse to download if larger than 1000 bytes! */
+ curl_easy_setopt(curl, CURLOPT_MAXFILESIZE, 1000L);
+ ret = curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
FTP, HTTP and MQTT
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode ret;
- curl_off_t ridiculous = 1 << 48;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- /* refuse to download if larger than ridiculous */
- curl_easy_setopt(curl, CURLOPT_MAXFILESIZE_LARGE, ridiculous);
- ret = curl_easy_perform(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode ret;
+ curl_off_t ridiculous = (curl_off_t)1 << 48;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ /* refuse to download if larger than ridiculous */
+ curl_easy_setopt(curl, CURLOPT_MAXFILESIZE_LARGE, ridiculous);
+ ret = curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ 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);
+ /* only allow each connection to be reused for 30 seconds */
+ curl_easy_setopt(curl, CURLOPT_MAXLIFETIME_CONN, 30L);
- curl_easy_perform(curl);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP(S)
.SH EXAMPLE
.nf
-curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- /* enable redirect following */
- curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
+ /* enable redirect following */
+ curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
- /* allow three redirects */
- curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 3L);
+ /* allow three redirects */
+ curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 3L);
- /* Perform the request */
- curl_easy_perform(curl);
+ /* Perform the request */
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
All but file://
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode ret;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- /* cap the download speed to 31415 bytes/sec */
- curl_easy_setopt(curl, CURLOPT_MAX_RECV_SPEED_LARGE, (curl_off_t)31415);
- ret = curl_easy_perform(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode ret;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ /* cap the download speed to 31415 bytes/sec */
+ curl_easy_setopt(curl, CURLOPT_MAX_RECV_SPEED_LARGE, (curl_off_t)31415);
+ ret = curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
All except file://
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode ret;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- /* cap the upload speed to 1000 bytes/sec */
- curl_easy_setopt(curl, CURLOPT_MAX_SEND_SPEED_LARGE, (curl_off_t)1000);
- /* (set some upload options as well!) */
- ret = curl_easy_perform(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode ret;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ /* cap the upload speed to 1000 bytes/sec */
+ curl_easy_setopt(curl, CURLOPT_MAX_SEND_SPEED_LARGE, (curl_off_t)1000);
+ /* (set some upload options as well!) */
+ ret = curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP, SMTP, IMAP.
.SH EXAMPLE
.nf
- curl_mime *multipart = curl_mime_init(handle);
- curl_mimepart *part = curl_mime_addpart(multipart);
- curl_mime_name(part, "name");
- curl_mime_data(part, "daniel", CURL_ZERO_TERMINATED);
- part = curl_mime_addpart(multipart);
- curl_mime_name(part, "project");
- curl_mime_data(part, "curl", CURL_ZERO_TERMINATED);
- part = curl_mime_addpart(multipart);
- curl_mime_name(part, "logotype-image");
- curl_mime_filedata(part, "curl.png");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_mime *multipart = curl_mime_init(curl);
+ if(multipart) {
+ curl_mimepart *part = curl_mime_addpart(multipart);
+ curl_mime_name(part, "name");
+ curl_mime_data(part, "daniel", CURL_ZERO_TERMINATED);
+ part = curl_mime_addpart(multipart);
+ curl_mime_name(part, "project");
+ curl_mime_data(part, "curl", CURL_ZERO_TERMINATED);
+ part = curl_mime_addpart(multipart);
+ curl_mime_name(part, "logotype-image");
+ curl_mime_filedata(part, "curl.png");
- /* Set the form info */
- curl_easy_setopt(handle, CURLOPT_MIMEPOST, multipart);
+ /* Set the form info */
+ curl_easy_setopt(curl, CURLOPT_MIMEPOST, multipart);
- curl_easy_perform(handle); /* post away! */
-
- curl_mime_free(multipart); /* free the post data */
+ curl_easy_perform(curl); /* post away! */
+ curl_mime_free(multipart); /* free the post data */
+ }
+ }
+}
.fi
.SH AVAILABILITY
Added in 7.56.0
HTTP, IMAP, SMTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-curl_mime *form = NULL;
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ curl_mime *form = NULL;
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- curl_easy_setopt(curl, CURLOPT_MIME_OPTIONS, CURLMIMEOPT_FORMESCAPE);
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ curl_easy_setopt(curl, CURLOPT_MIME_OPTIONS, CURLMIMEOPT_FORMESCAPE);
- form = curl_mime_init(curl);
- if(form) {
- curl_mimepart *part = curl_mime_addpart(form);
+ form = curl_mime_init(curl);
+ if(form) {
+ curl_mimepart *part = curl_mime_addpart(form);
- if(part) {
- curl_mime_filedata(part, "strange\\\\file\\\\name");
- curl_mime_name(part, "strange\\"field\\"name");
- curl_easy_setopt(curl, CURLOPT_MIMEPOST, form);
+ if(part) {
+ curl_mime_filedata(part, "strange\\\\file\\\\name");
+ curl_mime_name(part, "strange\\"field\\"name");
+ curl_easy_setopt(curl, CURLOPT_MIMEPOST, form);
- /* Perform the request */
- curl_easy_perform(curl);
+ /* Perform the request */
+ curl_easy_perform(curl);
+ }
}
- }
- curl_easy_cleanup(curl);
- curl_mime_free(mime);
+ curl_easy_cleanup(curl);
+ curl_mime_free(form);
+ }
}
.fi
.SH AVAILABILITY
Most
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode ret;
- curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/");
- curl_easy_setopt(curl, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
- ret = curl_easy_perform(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode ret;
+ curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/");
+ curl_easy_setopt(curl, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
+ ret = curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode ret;
- curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/");
- curl_easy_setopt(curl, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
- curl_easy_setopt(curl, CURLOPT_NETRC_FILE, "/tmp/magic-netrc");
- ret = curl_easy_perform(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode ret;
+ curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/");
+ curl_easy_setopt(curl, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
+ curl_easy_setopt(curl, CURLOPT_NETRC_FILE, "/tmp/magic-netrc");
+ ret = curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
SFTP, SCP and FILE
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode ret;
- curl_easy_setopt(curl, CURLOPT_URL, "sftp://upload.example.com/newdir/file.zip");
- curl_easy_setopt(curl, CURLOPT_FTP_CREATE_MISSING_DIRS, 1L);
- curl_easy_setopt(curl, CURLOPT_NEW_DIRECTORY_PERMS, 0644L);
- ret = curl_easy_perform(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode ret;
+ curl_easy_setopt(curl, CURLOPT_URL,
+ "sftp://upload.example.com/newdir/file.zip");
+ curl_easy_setopt(curl, CURLOPT_FTP_CREATE_MISSING_DIRS, 1L);
+ curl_easy_setopt(curl, CURLOPT_NEW_DIRECTORY_PERMS, 0644L);
+ ret = curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
SFTP, SCP and FILE
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode ret;
- curl_easy_setopt(curl, CURLOPT_URL, "sftp://upload.example.com/file.txt");
- curl_easy_setopt(curl, CURLOPT_NEW_FILE_PERMS, 0664L);
- ret = curl_easy_perform(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode ret;
+ curl_easy_setopt(curl, CURLOPT_URL, "sftp://upload.example.com/file.txt");
+ curl_easy_setopt(curl, CURLOPT_NEW_FILE_PERMS, 0664L);
+ ret = curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
Most
.SH EXAMPLE
.nf
-curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ 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);
+ /* get us the resource without a body - use HEAD! */
+ curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);
- /* Perform the request */
- curl_easy_perform(curl);
+ /* Perform the request */
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* enable progress meter */
- curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
+ /* enable progress meter */
+ curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
- /* Perform the request */
- curl_easy_perform(curl);
+ /* Perform the request */
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
Most
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- /* accept various URLs */
- curl_easy_setopt(curl, CURLOPT_URL, input);
- /* use this proxy */
- curl_easy_setopt(curl, CURLOPT_PROXY, "http://proxy:80");
- /* ... but make sure this host name is not proxied */
- curl_easy_setopt(curl, CURLOPT_NOPROXY, "www.example.com");
- curl_easy_perform(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ /* accept various URLs */
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ /* use this proxy */
+ curl_easy_setopt(curl, CURLOPT_PROXY, "http://proxy:80");
+ /* ... but make sure this host name is not proxied */
+ curl_easy_setopt(curl, CURLOPT_NOPROXY, "www.example.com");
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
+ curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
- ret = curl_easy_perform(curl);
+ res = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
return CURL_SOCKOPT_ALREADY_CONNECTED;
}
-curl = curl_easy_init();
-if(curl) {
- /* libcurl thinks that you connect to the host
- * and port that you specify in the URL option. */
- curl_easy_setopt(curl, CURLOPT_URL, "http://99.99.99.99:9999");
- /* call this function to get a socket */
- curl_easy_setopt(curl, CURLOPT_OPENSOCKETFUNCTION, opensocket);
- curl_easy_setopt(curl, CURLOPT_OPENSOCKETDATA, &sockfd);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ extern int sockfd; /* the already connected one */
+
+ /* libcurl thinks that you connect to the host
+ * and port that you specify in the URL option. */
+ curl_easy_setopt(curl, CURLOPT_URL, "http://99.99.99.99:9999");
+ /* call this function to get a socket */
+ curl_easy_setopt(curl, CURLOPT_OPENSOCKETFUNCTION, opensocket);
+ curl_easy_setopt(curl, CURLOPT_OPENSOCKETDATA, &sockfd);
- /* call this function to set options for the socket */
- curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockopt_callback);
+ /* call this function to set options for the socket */
+ curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockopt_callback);
- res = curl_easy_perform(curl);
+ res = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
return CURL_SOCKOPT_ALREADY_CONNECTED;
}
-curl = curl_easy_init();
-if(curl) {
- /* libcurl thinks that you connect to the host
- * and port that you specify in the URL option. */
- curl_easy_setopt(curl, CURLOPT_URL, "http://99.99.99.99:9999");
- /* call this function to get a socket */
- curl_easy_setopt(curl, CURLOPT_OPENSOCKETFUNCTION, opensocket);
- curl_easy_setopt(curl, CURLOPT_OPENSOCKETDATA, &sockfd);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ extern int sockfd; /* the already connected one */
+ /* libcurl thinks that you connect to the host
+ * and port that you specify in the URL option. */
+ curl_easy_setopt(curl, CURLOPT_URL, "http://99.99.99.99:9999");
+ /* call this function to get a socket */
+ curl_easy_setopt(curl, CURLOPT_OPENSOCKETFUNCTION, opensocket);
+ curl_easy_setopt(curl, CURLOPT_OPENSOCKETDATA, &sockfd);
- /* call this function to set options for the socket */
- curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockopt_callback);
+ /* call this function to set options for the socket */
+ curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockopt_callback);
- res = curl_easy_perform(curl);
+ res = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
Most
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
- curl_easy_setopt(curl, CURLOPT_PASSWORD, "qwerty");
+ curl_easy_setopt(curl, CURLOPT_PASSWORD, "qwerty");
- ret = curl_easy_perform(curl);
+ res = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/../../etc/password");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL,
+ "https://example.com/../../etc/password");
- curl_easy_setopt(curl, CURLOPT_PATH_AS_IS, 1L);
+ curl_easy_setopt(curl, CURLOPT_PATH_AS_IS, 1L);
- curl_easy_perform(curl);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
All TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- curl_easy_setopt(curl, CURLOPT_PINNEDPUBLICKEY, "/etc/publickey.der");
- /* OR
- curl_easy_setopt(curl, CURLOPT_PINNEDPUBLICKEY, "sha256//YhKJKSzoTt2b5FP18fvpHo7fJYqQCjAa3HWY3tvRMwE=;sha256//t62CeU2tQiqkexU74Gxa2eg7fRbEgoChTociMee9wno=");
- */
-
- /* Perform the request */
- curl_easy_perform(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ curl_easy_setopt(curl, CURLOPT_PINNEDPUBLICKEY, "/etc/publickey.der");
+ /* OR
+ curl_easy_setopt(curl, CURLOPT_PINNEDPUBLICKEY,
+ "sha256//YhKJKSzoTt2b5FP18fvpHo7fJYqQCjAa3HWY3"
+ "tvRMwE=;sha256//t62CeU2tQiqkexU74Gxa2eg7fRbEg"
+ "oChTociMee9wno=");
+ */
+
+ /* Perform the request */
+ curl_easy_perform(curl);
+ }
}
.fi
.SH PUBLIC KEY EXTRACTION
HTTP(S)
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_PIPEWAIT, 1L);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_PIPEWAIT, 1L);
- /* now add this easy handle to the multi handle */
+ /* now add this easy handle to the multi handle */
+ }
}
.fi
.SH AVAILABILITY
Used for all protocols that speak to a port number.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
- curl_easy_setopt(curl, CURLOPT_PORT, 8080L);
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
+ curl_easy_setopt(curl, CURLOPT_PORT, 8080L);
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
- curl_easy_setopt(curl, CURLOPT_POST, 1L);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
+ curl_easy_setopt(curl, CURLOPT_POST, 1L);
- /* set up the read callback with CURLOPT_READFUNCTION */
+ /* set up the read callback with CURLOPT_READFUNCTION */
- ret = curl_easy_perform(curl);
+ res = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
.SH EXAMPLE
.nf
/* send an application/x-www-form-urlencoded POST */
-CURL *curl = curl_easy_init();
-if(curl) {
- const char *data = "data to send";
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ const char *data = "data to send";
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* size of the POST data if strlen() is not good enough */
- curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, 12L);
+ /* size of the POST data if strlen() is not good enough */
+ curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, 12L);
- /* pass in a pointer to the data - libcurl does not copy */
- curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
+ /* pass in a pointer to the data - libcurl does not copy */
+ curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
- curl_easy_perform(curl);
-}
+ curl_easy_perform(curl);
+ }
-/* send an application/json POST */
-CURL *curl = curl_easy_init();
-if(curl) {
- const char *json = "{\"name\": \"daniel\"}";
- struct curl_slist *slist1 = NULL;
- slist1 = curl_slist_append(slist1, "Content-Type: application/json");
- slist1 = curl_slist_append(slist1, "Accept: application/json");
+ /* send an application/json POST */
+ curl = curl_easy_init();
+ if(curl) {
+ const char *json = "{\"name\": \"daniel\"}";
+ struct curl_slist *slist1 = NULL;
+ slist1 = curl_slist_append(slist1, "Content-Type: application/json");
+ slist1 = curl_slist_append(slist1, "Accept: application/json");
- /* set custom headers */
- curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, slist1);
+ /* set custom headers */
+ curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist1);
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* pass in a pointer to the data - libcurl does not copy */
- curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json);
+ /* pass in a pointer to the data - libcurl does not copy */
+ curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json);
- curl_easy_perform(curl);
+ curl_easy_perform(curl);
+ }
}
-
.fi
.SH AVAILABILITY
Always
HTTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- const char *data = "data to send";
+#include <string.h> /* for strlen */
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ const char *data = "data to send";
- /* size of the POST data */
- curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long) strlen(data));
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
+ /* size of the POST data */
+ curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long) strlen(data));
- curl_easy_perform(curl);
+ curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
+
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP(S)
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- const char *data = large_chunk;
- curl_off_t length_of_data; /* set somehow */
+extern char *large_chunk; /* pointer to somewhere */
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ const char *data = large_chunk;
+ curl_off_t length_of_data; /* set somehow */
- /* size of the POST data */
- curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE_LARGE, length_of_data);
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
+ /* size of the POST data */
+ curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE_LARGE, length_of_data);
- curl_easy_perform(curl);
+ curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
+
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
SFTP and FTP
.SH EXAMPLE
.nf
-struct curl_slist *cmdlist = NULL;
-cmdlist = curl_slist_append(cmdlist, "RNFR source-name");
-cmdlist = curl_slist_append(cmdlist, "RNTO new-name");
+int main(void)
+{
+ struct curl_slist *cmdlist = NULL;
+ cmdlist = curl_slist_append(cmdlist, "RNFR source-name");
+ cmdlist = curl_slist_append(cmdlist, "RNTO new-name");
-curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/foo.bin");
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/foo.bin");
- /* pass in the FTP commands to run after the transfer */
- curl_easy_setopt(curl, CURLOPT_POSTQUOTE, cmdlist);
+ /* pass in the FTP commands to run after the transfer */
+ curl_easy_setopt(curl, CURLOPT_POSTQUOTE, cmdlist);
- ret = curl_easy_perform(curl);
+ res = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP(S)
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* a silly POST example */
- curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "data=true");
+ /* a silly POST example */
+ curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "data=true");
- /* example.com is redirected, so we tell libcurl to send POST on 301, 302 and
- 303 HTTP response codes */
- curl_easy_setopt(curl, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL);
+ /* example.com is redirected, so we tell libcurl to send POST on 301,
+ 302 and 303 HTTP response codes */
+ curl_easy_setopt(curl, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL);
- curl_easy_perform(curl);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
FTP
.SH EXAMPLE
.nf
-struct curl_slist *cmdlist = NULL;
-cmdlist = curl_slist_append(cmdlist, "SYST");
+int main(void)
+{
+ struct curl_slist *cmdlist = NULL;
+ cmdlist = curl_slist_append(cmdlist, "SYST");
-curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/foo.bin");
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/foo.bin");
- /* pass in the FTP commands to run */
- curl_easy_setopt(curl, CURLOPT_PREQUOTE, cmdlist);
+ /* pass in the FTP commands to run */
+ curl_easy_setopt(curl, CURLOPT_PREQUOTE, cmdlist);
- ret = curl_easy_perform(curl);
+ res = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
+struct priv {
+ void *custom;
+};
+
static int prereq_callback(void *clientp,
char *conn_primary_ip,
char *conn_local_ip,
int conn_primary_port,
int conn_local_port)
{
- printf("Connection made to %s:%s\\n", conn_primary_ip, conn_primary_port);
+ printf("Connection made to %s:%d\\n", conn_primary_ip, conn_primary_port);
return CURL_PREREQFUNC_OK;
}
+int main(void)
{
- struct data prereq_data;
- curl_easy_setopt(CURL *handle, CURLOPT_PREREQFUNCTION, prereq_callback);
- curl_easy_setopt(CURL *handle, CURLOPT_PREREQDATA, &prereq_data);
+ struct priv prereq_data;
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_PREREQFUNCTION, prereq_callback);
+ curl_easy_setopt(curl, CURLOPT_PREREQDATA, &prereq_data);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
ALL
.SH EXAMPLE
.nf
+struct priv {
+ void *custom;
+};
+
static int prereq_callback(void *clientp,
char *conn_primary_ip,
char *conn_local_ip,
int conn_primary_port,
int conn_local_port)
{
- printf("Connection made to %s:%s\\n", conn_primary_ip, conn_primary_port);
+ printf("Connection made to %s:%d\\n", conn_primary_ip, conn_primary_port);
return CURL_PREREQFUNC_OK;
}
+int main(void)
{
- struct data prereq_data;
- curl_easy_setopt(CURL *handle, CURLOPT_PREREQFUNCTION, prereq_callback);
- curl_easy_setopt(CURL *handle, CURLOPT_PREREQDATA, &prereq_data);
+ struct priv prereq_data;
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_PREREQFUNCTION, prereq_callback);
+ curl_easy_setopt(curl, CURLOPT_PREREQDATA, &prereq_data);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
All except file://. Note that some protocols do not work well over proxy.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- 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);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ 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);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-struct private secrets;
-if(curl) {
- struct private *extracted;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+struct private {
+ void *custom;
+};
- /* store a pointer to our private struct */
- curl_easy_setopt(curl, CURLOPT_PRIVATE, &secrets);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ struct private secrets;
+ if(curl) {
+ struct private *extracted;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- curl_easy_perform(curl);
+ /* store a pointer to our private struct */
+ curl_easy_setopt(curl, CURLOPT_PRIVATE, &secrets);
- /* we can extract the private pointer again too */
- curl_easy_getinfo(curl, CURLINFO_PRIVATE, &extracted);
+ curl_easy_perform(curl);
+
+ /* we can extract the private pointer again too */
+ curl_easy_getinfo(curl, CURLINFO_PRIVATE, &extracted);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
- struct progress {
- char *private;
- size_t size;
- };
+struct progress {
+ char *private;
+ size_t size;
+};
- static size_t progress_callback(void *clientp,
- double dltotal,
- double dlnow,
- double ultotal,
- double ulnow)
- {
- struct memory *progress = (struct progress *)clientp;
+static size_t progress_callback(void *clientp,
+ double dltotal,
+ double dlnow,
+ double ultotal,
+ double ulnow)
+{
+ struct progress *memory = clientp;
+ printf("private: %p\\n", memory->private);
- /* use the values */
+ /* use the values */
- return 0; /* all is good */
- }
+ return 0; /* all is good */
+}
- struct progress data;
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ struct progress data;
- /* pass struct to callback */
- curl_easy_setopt(curl_handle, CURLOPT_PROGRESSDATA, &data);
+ /* pass struct to callback */
+ curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &data);
+ curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback);
- curl_easy_setopt(curl_handle, CURLOPT_PROGRESSFUNCTION, progress_callback);
+ curl_easy_perform(curl);
+ }
+}
.fi
.SH AVAILABILITY
Always
All
.SH EXAMPLE
.nf
- struct progress {
- char *private;
- size_t size;
- };
-
- static size_t progress_callback(void *clientp,
- double dltotal,
- double dlnow,
- double ultotal,
- double ulnow)
- {
- struct progress *memory = (struct progress *)clientp;
-
- /* use the values */
-
- return 0; /* all is good */
- }
-
- struct progress data;
-
- /* pass struct to callback */
- curl_easy_setopt(curl_handle, CURLOPT_PROGRESSDATA, &data);
-
- curl_easy_setopt(curl_handle, CURLOPT_PROGRESSFUNCTION, progress_callback);
+struct progress {
+ char *private;
+ size_t size;
+};
+
+static size_t progress_callback(void *clientp,
+ double dltotal,
+ double dlnow,
+ double ultotal,
+ double ulnow)
+{
+ struct progress *memory = clientp;
+ printf("private: %p\\n", memory->private);
+
+ /* use the values */
+
+ return 0; /* all is good */
+}
+
+int main(void)
+{
+ struct progress data;
+
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ /* pass struct to callback */
+ curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &data);
+ curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback);
+
+ curl_easy_perform(curl);
+ }
+}
.fi
.SH AVAILABILITY
Deprecated since 7.32.0.
All
.SH EXAMPLE
.nf
-curl = curl_easy_init();
-if(curl) {
- /* pass in the URL from an external source */
- curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
+int main(int argc, char **argv)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ /* pass in the URL from an external source */
+ curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
- /* only allow HTTP, TFTP and SFTP */
- curl_easy_setopt(curl, CURLOPT_PROTOCOLS,
- CURLPROTO_HTTP | CURLPROTO_TFTP | CURLPROTO_SFTP);
+ /* only allow HTTP, TFTP and SFTP */
+ curl_easy_setopt(curl, CURLOPT_PROTOCOLS,
+ CURLPROTO_HTTP | CURLPROTO_TFTP | CURLPROTO_SFTP);
- /* Perform the request */
- curl_easy_perform(curl);
+ /* Perform the request */
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-curl = curl_easy_init();
-if(curl) {
- /* pass in the URL from an external source */
- curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
+int main(int argc, char **argv)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ /* pass in the URL from an external source */
+ curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
- /* only allow HTTP, TFTP and SFTP */
- curl_easy_setopt(curl, CURLOPT_PROTOCOLS_STR, "http,tftp,sftp");
+ /* only allow HTTP, TFTP and SFTP */
+ curl_easy_setopt(curl, CURLOPT_PROTOCOLS_STR, "http,tftp,sftp");
- /* Perform the request */
- curl_easy_perform(curl);
+ /* Perform the request */
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
All except file://. Note that some protocols do not work well over proxy.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/file.txt");
- curl_easy_setopt(curl, CURLOPT_PROXY, "http://proxy:80");
- curl_easy_perform(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/file.txt");
+ curl_easy_setopt(curl, CURLOPT_PROXY, "http://proxy:80");
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode ret;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- /* use this proxy */
- curl_easy_setopt(curl, CURLOPT_PROXY, "http://local.example.com:1080");
- /* allow whatever auth the proxy speaks */
- curl_easy_setopt(curl, CURLOPT_PROXYAUTH, CURLAUTH_ANY);
- /* set the proxy credentials */
- curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, "james:007");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode ret;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ /* use this proxy */
+ curl_easy_setopt(curl, CURLOPT_PROXY, "http://local.example.com:1080");
+ /* allow whatever auth the proxy speaks */
+ curl_easy_setopt(curl, CURLOPT_PROXYAUTH, CURLAUTH_ANY);
+ /* set the proxy credentials */
+ curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, "james:007");
+ ret = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
+int main(void)
+{
+ CURL *curl = curl_easy_init();
-struct curl_slist *list;
+ struct curl_slist *list;
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- curl_easy_setopt(curl, CURLOPT_PROXY, "http://proxy.example.com:80");
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ curl_easy_setopt(curl, CURLOPT_PROXY, "http://proxy.example.com:80");
- list = curl_slist_append(NULL, "Shoesize: 10");
- list = curl_slist_append(list, "Accept:");
+ list = curl_slist_append(NULL, "Shoesize: 10");
+ list = curl_slist_append(list, "Accept:");
- curl_easy_setopt(curl, CURLOPT_PROXYHEADER, list);
+ curl_easy_setopt(curl, CURLOPT_PROXYHEADER, list);
- curl_easy_perform(curl);
+ curl_easy_perform(curl);
- curl_slist_free_all(list); /* free the list again */
+ curl_slist_free_all(list); /* free the list again */
+ }
}
.fi
.SH AVAILABILITY
Most
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
- curl_easy_setopt(curl, CURLOPT_PROXY, "http://localhost:8080");
- curl_easy_setopt(curl, CURLOPT_PROXYUSERNAME, "mrsmith");
- curl_easy_setopt(curl, CURLOPT_PROXYPASSWORD, "qwerty");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
+ curl_easy_setopt(curl, CURLOPT_PROXY, "http://localhost:8080");
+ curl_easy_setopt(curl, CURLOPT_PROXYUSERNAME, "mrsmith");
+ curl_easy_setopt(curl, CURLOPT_PROXYPASSWORD, "qwerty");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
- curl_easy_setopt(curl, CURLOPT_PROXY, "localhost");
- curl_easy_setopt(curl, CURLOPT_PROXYPORT, 8080L);
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
+ curl_easy_setopt(curl, CURLOPT_PROXY, "localhost");
+ curl_easy_setopt(curl, CURLOPT_PROXYPORT, 8080L);
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
Most
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode ret;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_PROXY, "local.example.com:1080");
- /* set the proxy type */
- curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode ret;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_PROXY, "local.example.com:1080");
+ /* set the proxy type */
+ curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
+ ret = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
Most
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
- curl_easy_setopt(curl, CURLOPT_PROXY, "http://localhost:8080");
- curl_easy_setopt(curl, CURLOPT_PROXYUSERNAME, "mrsmith");
- curl_easy_setopt(curl, CURLOPT_PROXYPASSWORD, "qwerty");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
+ curl_easy_setopt(curl, CURLOPT_PROXY, "http://localhost:8080");
+ curl_easy_setopt(curl, CURLOPT_PROXYUSERNAME, "mrsmith");
+ curl_easy_setopt(curl, CURLOPT_PROXYPASSWORD, "qwerty");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
Used with all protocols that can use a proxy
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
- curl_easy_setopt(curl, CURLOPT_PROXY, "http://localhost:8080");
- curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, "clark%20kent:superman");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
+ curl_easy_setopt(curl, CURLOPT_PROXY, "http://localhost:8080");
+ curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, "clark%20kent:superman");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
Used with HTTPS proxy
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- /* using an HTTPS proxy */
- curl_easy_setopt(curl, CURLOPT_PROXY, "https://localhost:443");
- curl_easy_setopt(curl, CURLOPT_PROXY_CAINFO, "/etc/certs/cabundle.pem");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ /* using an HTTPS proxy */
+ curl_easy_setopt(curl, CURLOPT_PROXY, "https://localhost:443");
+ curl_easy_setopt(curl, CURLOPT_PROXY_CAINFO, "/etc/certs/cabundle.pem");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
Used with HTTPS proxy
.SH EXAMPLE
.nf
-char *strpem; /* strpem must point to a PEM string */
-CURL *curl = curl_easy_init();
-if(curl) {
- struct curl_blob blob;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- /* using an HTTPS proxy */
- curl_easy_setopt(curl, CURLOPT_PROXY, "https://localhost:443");
- blob.data = strpem;
- blob.len = strlen(strpem);
- blob.flags = CURL_BLOB_COPY;
- curl_easy_setopt(curl, CURLOPT_PROXY_CAINFO_BLOB, &blob);
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+#include <string.h> /* for strlen */
+
+extern char *strpem; /* strpem must point to a PEM string */
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ struct curl_blob blob;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ /* using an HTTPS proxy */
+ curl_easy_setopt(curl, CURLOPT_PROXY, "https://localhost:443");
+ blob.data = strpem;
+ blob.len = strlen(strpem);
+ blob.flags = CURL_BLOB_COPY;
+ curl_easy_setopt(curl, CURLOPT_PROXY_CAINFO_BLOB, &blob);
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
Everything used over an HTTPS proxy
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- /* using an HTTPS proxy */
- curl_easy_setopt(curl, CURLOPT_PROXY, "https://localhost:443");
- curl_easy_setopt(curl, CURLOPT_PROXY_CAPATH, "/etc/cert-dir");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ /* using an HTTPS proxy */
+ curl_easy_setopt(curl, CURLOPT_PROXY, "https://localhost:443");
+ curl_easy_setopt(curl, CURLOPT_PROXY_CAPATH, "/etc/cert-dir");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
Used with HTTPS proxy.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_PROXY, "https://localhost:80");
- curl_easy_setopt(curl, CURLOPT_PROXY_CRLFILE, "/etc/certs/crl.pem");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_PROXY, "https://localhost:80");
+ curl_easy_setopt(curl, CURLOPT_PROXY_CRLFILE, "/etc/certs/crl.pem");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All TLS-based protocols
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- /* using an HTTPS proxy */
- curl_easy_setopt(curl, CURLOPT_PROXY, "https://localhost:443");
- curl_easy_setopt(curl, CURLOPT_PROXY_ISSUERCERT, "/etc/certs/cacert.pem");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ /* using an HTTPS proxy */
+ curl_easy_setopt(curl, CURLOPT_PROXY, "https://localhost:443");
+ curl_easy_setopt(curl, CURLOPT_PROXY_ISSUERCERT, "/etc/certs/cacert.pem");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All TLS-based protocols
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- struct curl_blob blob;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- /* using an HTTPS proxy */
- curl_easy_setopt(curl, CURLOPT_PROXY, "https://localhost:443");
- blob.data = certificateData;
- blob.len = filesize;
- blob.flags = CURL_BLOB_COPY;
- curl_easy_setopt(curl, CURLOPT_PROXY_ISSUERCERT_BLOB, &blob);
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+
+extern char *certificateData; /* point to the data */
+size_t filesize; /* size of the data */
+
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ struct curl_blob blob;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ /* using an HTTPS proxy */
+ curl_easy_setopt(curl, CURLOPT_PROXY, "https://localhost:443");
+ blob.data = certificateData;
+ blob.len = filesize;
+ blob.flags = CURL_BLOB_COPY;
+ curl_easy_setopt(curl, CURLOPT_PROXY_ISSUERCERT_BLOB, &blob);
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
Used with HTTPS proxy
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
- curl_easy_setopt(curl, CURLOPT_PROXY, "https://proxy:443");
- curl_easy_setopt(curl, CURLOPT_PROXY_KEYPASSWD, "superman");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
+ curl_easy_setopt(curl, CURLOPT_PROXY, "https://proxy:443");
+ curl_easy_setopt(curl, CURLOPT_PROXY_KEYPASSWD, "superman");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- curl_easy_setopt(curl, CURLOPT_PROXY, "https://proxy:443");
- curl_easy_setopt(curl, CURLOPT_PROXY_PINNEDPUBLICKEY,
- "sha256//YhKJKSzoTt2b5FP18fvpHo7fJYqQCjAa3HWY3tvRMwE=;sha256//t62CeU2tQiqkexU74Gxa2eg7fRbEgoChTociMee9wno=");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ curl_easy_setopt(curl, CURLOPT_PROXY, "https://proxy:443");
+ curl_easy_setopt(curl, CURLOPT_PROXY_PINNEDPUBLICKEY,
+ "sha256//YhKJKSzoTt2b5FP18fvpHo7fJYqQCjA"
+ "a3HWY3tvRMwE=;sha256//t62CeU2tQiqkexU74"
+ "Gxa2eg7fRbEgoChTociMee9wno=");
- /* Perform the request */
- curl_easy_perform(curl);
+ /* Perform the request */
+ curl_easy_perform(curl);
+ }
}
.fi
.SH PUBLIC KEY EXTRACTION
All network protocols
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode ret;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_PROXY_SERVICE_NAME, "custom");
- ret = curl_easy_perform(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode ret;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_PROXY_SERVICE_NAME, "custom");
+ ret = curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
Used with HTTPS proxy
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_PROXY, "https://proxy");
- curl_easy_setopt(curl, CURLOPT_PROXY_SSLCERT, "client.pem");
- curl_easy_setopt(curl, CURLOPT_PROXY_SSLKEY, "key.pem");
- curl_easy_setopt(curl, CURLOPT_PROXY_KEYPASSWD, "s3cret");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_PROXY, "https://proxy");
+ curl_easy_setopt(curl, CURLOPT_PROXY_SSLCERT, "client.pem");
+ curl_easy_setopt(curl, CURLOPT_PROXY_SSLKEY, "key.pem");
+ curl_easy_setopt(curl, CURLOPT_PROXY_KEYPASSWD, "s3cret");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_PROXY, "https://proxy");
- curl_easy_setopt(curl, CURLOPT_PROXY_SSLCERT, "client.pem");
- curl_easy_setopt(curl, CURLOPT_PROXY_SSLCERTTYPE, "PEM");
- curl_easy_setopt(curl, CURLOPT_PROXY_SSLKEY, "key.pem");
- curl_easy_setopt(curl, CURLOPT_PROXY_KEYPASSWD, "s3cret");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_PROXY, "https://proxy");
+ curl_easy_setopt(curl, CURLOPT_PROXY_SSLCERT, "client.pem");
+ curl_easy_setopt(curl, CURLOPT_PROXY_SSLCERTTYPE, "PEM");
+ curl_easy_setopt(curl, CURLOPT_PROXY_SSLKEY, "key.pem");
+ curl_easy_setopt(curl, CURLOPT_PROXY_KEYPASSWD, "s3cret");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
Used with HTTPS proxy
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- struct curl_blob blob;
- blob.data = certificateData;
- blob.len = filesize;
- blob.flags = CURL_BLOB_COPY;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_PROXY, "https://proxy");
- curl_easy_setopt(curl, CURLOPT_PROXY_SSLKEY, "key.pem");
- curl_easy_setopt(curl, CURLOPT_PROXY_KEYPASSWD, "s3cret");
- curl_easy_setopt(curl, CURLOPT_PROXY_SSLCERT_BLOB, &blob);
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+
+extern char *certificateData; /* point to data */
+extern size_t filesize; /* size of the data */
+
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ struct curl_blob blob;
+ blob.data = certificateData;
+ blob.len = filesize;
+ blob.flags = CURL_BLOB_COPY;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_PROXY, "https://proxy");
+ curl_easy_setopt(curl, CURLOPT_PROXY_SSLKEY, "key.pem");
+ curl_easy_setopt(curl, CURLOPT_PROXY_KEYPASSWD, "s3cret");
+ curl_easy_setopt(curl, CURLOPT_PROXY_SSLCERT_BLOB, &blob);
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_PROXY, "https://proxy");
- curl_easy_setopt(curl, CURLOPT_PROXY_SSLCERT, "client.pem");
- curl_easy_setopt(curl, CURLOPT_PROXY_SSLKEY, "key.pem");
- curl_easy_setopt(curl, CURLOPT_PROXY_KEYPASSWD, "s3cret");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_PROXY, "https://proxy");
+ curl_easy_setopt(curl, CURLOPT_PROXY_SSLCERT, "client.pem");
+ curl_easy_setopt(curl, CURLOPT_PROXY_SSLKEY, "key.pem");
+ curl_easy_setopt(curl, CURLOPT_PROXY_KEYPASSWD, "s3cret");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
Used with HTTPS proxy
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_PROXY, "https://proxy");
- curl_easy_setopt(curl, CURLOPT_PROXY_SSLCERT, "client.pem");
- curl_easy_setopt(curl, CURLOPT_PROXY_SSLKEY, "key.pem");
- curl_easy_setopt(curl, CURLOPT_PROXY_SSLKEYTYPE, "PEM");
- curl_easy_setopt(curl, CURLOPT_PROXY_KEYPASSWD, "s3cret");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_PROXY, "https://proxy");
+ curl_easy_setopt(curl, CURLOPT_PROXY_SSLCERT, "client.pem");
+ curl_easy_setopt(curl, CURLOPT_PROXY_SSLKEY, "key.pem");
+ curl_easy_setopt(curl, CURLOPT_PROXY_SSLKEYTYPE, "PEM");
+ curl_easy_setopt(curl, CURLOPT_PROXY_KEYPASSWD, "s3cret");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- struct curl_blob blob;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_PROXY, "https://proxy");
- blob.data = certificateData;
- blob.len = filesize;
- blob.flags = CURL_BLOB_COPY;
- curl_easy_setopt(curl, CURLOPT_PROXY_SSLCERT_BLOB, &blob);
- curl_easy_setopt(curl, CURLOPT_PROXY_SSLCERTTYPE, "PEM");
- blob.data = privateKeyData;
- blob.len = privateKeySize;
- curl_easy_setopt(curl, CURLOPT_PROXY_SSLKEY_BLOB, &blob);
- curl_easy_setopt(curl, CURLOPT_PROXY_KEYPASSWD, "s3cret");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+extern char *certificateData; /* point to data */
+extern size_t filesize; /* size of data */
+
+extern char *privateKeyData; /* point to data */
+extern size_t privateKeySize; /* size */
+
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ struct curl_blob blob;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_PROXY, "https://proxy");
+ blob.data = certificateData;
+ blob.len = filesize;
+ blob.flags = CURL_BLOB_COPY;
+ curl_easy_setopt(curl, CURLOPT_PROXY_SSLCERT_BLOB, &blob);
+ curl_easy_setopt(curl, CURLOPT_PROXY_SSLCERTTYPE, "PEM");
+
+ blob.data = privateKeyData;
+ blob.len = privateKeySize;
+ curl_easy_setopt(curl, CURLOPT_PROXY_SSLKEY_BLOB, &blob);
+ curl_easy_setopt(curl, CURLOPT_PROXY_KEYPASSWD, "s3cret");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ 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);
+ /* 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);
+ /* Perform the request */
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_PROXY, "https://localhost");
- curl_easy_setopt(curl, CURLOPT_PROXY_SSL_CIPHER_LIST, "TLSv1");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_PROXY, "https://localhost");
+ curl_easy_setopt(curl, CURLOPT_PROXY_SSL_CIPHER_LIST, "TLSv1");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All TLS-based protocols
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_PROXY, "https://proxy");
- /* weaken TLS only for use with silly proxies */
- curl_easy_setopt(curl, CURLOPT_PROXY_SSL_OPTIONS, CURLSSLOPT_ALLOW_BEAST |
- CURLSSLOPT_NO_REVOKE);
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_PROXY, "https://proxy");
+ /* weaken TLS only for use with silly proxies */
+ curl_easy_setopt(curl, CURLOPT_PROXY_SSL_OPTIONS, CURLSSLOPT_ALLOW_BEAST |
+ CURLSSLOPT_NO_REVOKE);
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All protocols when used over an HTTPS proxy.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ 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);
+ /* Set the default value: strict name check please */
+ curl_easy_setopt(curl, CURLOPT_PROXY_SSL_VERIFYHOST, 2L);
- curl_easy_perform(curl);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ 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);
+ /* Set the default value: strict certificate check please */
+ curl_easy_setopt(curl, CURLOPT_PROXY_SSL_VERIFYPEER, 1L);
- curl_easy_perform(curl);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
All TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_PROXY_TLS13_CIPHERS,
- "TLS_CHACHA20_POLY1305_SHA256");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_PROXY_TLS13_CIPHERS,
+ "TLS_CHACHA20_POLY1305_SHA256");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_PROXY, "https://proxy");
- curl_easy_setopt(curl, CURLOPT_PROXY_TLSAUTH_TYPE, "SRP");
- curl_easy_setopt(curl, CURLOPT_PROXY_TLSAUTH_USERNAME, "user");
- curl_easy_setopt(curl, CURLOPT_PROXY_TLSAUTH_PASSWORD, "secret");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_PROXY, "https://proxy");
+ curl_easy_setopt(curl, CURLOPT_PROXY_TLSAUTH_TYPE, "SRP");
+ curl_easy_setopt(curl, CURLOPT_PROXY_TLSAUTH_USERNAME, "user");
+ curl_easy_setopt(curl, CURLOPT_PROXY_TLSAUTH_PASSWORD, "secret");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_PROXY, "https://proxy");
- curl_easy_setopt(curl, CURLOPT_PROXY_TLSAUTH_TYPE, "SRP");
- curl_easy_setopt(curl, CURLOPT_PROXY_TLSAUTH_USERNAME, "user");
- curl_easy_setopt(curl, CURLOPT_PROXY_TLSAUTH_PASSWORD, "secret");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_PROXY, "https://proxy");
+ curl_easy_setopt(curl, CURLOPT_PROXY_TLSAUTH_TYPE, "SRP");
+ curl_easy_setopt(curl, CURLOPT_PROXY_TLSAUTH_USERNAME, "user");
+ curl_easy_setopt(curl, CURLOPT_PROXY_TLSAUTH_PASSWORD, "secret");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_PROXY, "https://proxy");
- curl_easy_setopt(curl, CURLOPT_PROXY_TLSAUTH_TYPE, "SRP");
- curl_easy_setopt(curl, CURLOPT_PROXY_TLSAUTH_USERNAME, "user");
- curl_easy_setopt(curl, CURLOPT_PROXY_TLSAUTH_PASSWORD, "secret");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_PROXY, "https://proxy");
+ curl_easy_setopt(curl, CURLOPT_PROXY_TLSAUTH_TYPE, "SRP");
+ curl_easy_setopt(curl, CURLOPT_PROXY_TLSAUTH_USERNAME, "user");
+ curl_easy_setopt(curl, CURLOPT_PROXY_TLSAUTH_PASSWORD, "secret");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
FTP over proxy
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/old-server/file.txt");
- curl_easy_setopt(curl, CURLOPT_PROXY, "http://localhost:80");
- curl_easy_setopt(curl, CURLOPT_PROXY_TRANSFER_MODE, 1L);
- curl_easy_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL,
+ "ftp://example.com/old-server/file.txt");
+ curl_easy_setopt(curl, CURLOPT_PROXY, "http://localhost:80");
+ curl_easy_setopt(curl, CURLOPT_PROXY_TRANSFER_MODE, 1L);
+ curl_easy_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- /* we want to use our own read function */
- curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
+static size_t read_cb(char *ptr, size_t size, size_t nmemb, void *userdata)
+{
+ FILE *src = userdata;
+ /* copy as much data as possible into the 'ptr' buffer, but no more than
+ 'size' * 'nmemb' bytes! */
+ size_t retcode = fread(ptr, size, nmemb, src);
- /* enable PUT */
- curl_easy_setopt(curl, CURLOPT_PUT, 1L);
+ return retcode;
+}
+
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ FILE *src = fopen("local-file", "r");
+ curl_off_t fsize; /* set this to the size of the input file */
+
+ /* we want to use our own read function */
+ curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_cb);
+
+ /* enable PUT */
+ curl_easy_setopt(curl, CURLOPT_PUT, 1L);
- /* specify target */
- curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/dir/to/newfile");
+ /* specify target */
+ curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/dir/to/newfile");
- /* now specify which pointer to pass to our callback */
- curl_easy_setopt(curl, CURLOPT_READDATA, hd_src);
+ /* now specify which pointer to pass to our callback */
+ curl_easy_setopt(curl, CURLOPT_READDATA, src);
- /* Set the size of the file to upload */
- curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)fsize);
+ /* Set the size of the file to upload */
+ 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);
+ /* Now run off and do what you have been told! */
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode ret;
- curl_easy_setopt(curl, CURLOPT_QUICK_EXIT, 1L);
- ret = curl_easy_perform(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode ret;
+ curl_easy_setopt(curl, CURLOPT_QUICK_EXIT, 1L);
+ ret = curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
SFTP and FTP
.SH EXAMPLE
.nf
-struct curl_slist *cmdlist = NULL;
-cmdlist = curl_slist_append(cmdlist, "RNFR source-name");
-cmdlist = curl_slist_append(cmdlist, "RNTO new-name");
+int main(void)
+{
+ struct curl_slist *cmdlist = NULL;
+ cmdlist = curl_slist_append(cmdlist, "RNFR source-name");
+ cmdlist = curl_slist_append(cmdlist, "RNTO new-name");
-curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/foo.bin");
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/foo.bin");
- /* pass in the FTP commands to run before the transfer */
- curl_easy_setopt(curl, CURLOPT_QUOTE, cmdlist);
+ /* pass in the FTP commands to run before the transfer */
+ curl_easy_setopt(curl, CURLOPT_QUOTE, cmdlist);
- ret = curl_easy_perform(curl);
+ res = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_RANDOM_FILE, "junk.txt");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_RANDOM_FILE, "junk.txt");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP, FTP, FILE, RTSP and SFTP.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* get the first 200 bytes */
- curl_easy_setopt(curl, CURLOPT_RANGE, "0-199");
+ /* get the first 200 bytes */
+ curl_easy_setopt(curl, CURLOPT_RANGE, "0-199");
- /* Perform the request */
- curl_easy_perform(curl);
+ /* Perform the request */
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
This is used for all protocols when sending data.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-struct MyData this;
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+struct MyData {
+ void *custom;
+};
- /* pass pointer that gets passed in to the
- CURLOPT_READFUNCTION callback */
- curl_easy_setopt(curl, CURLOPT_READDATA, &this);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ struct MyData this;
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- curl_easy_perform(curl);
+ /* pass pointer that gets passed in to the
+ CURLOPT_READFUNCTION callback */
+ curl_easy_setopt(curl, CURLOPT_READDATA, &this);
+
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
return retcode;
}
-void setup(char *uploadthis)
+int main(int argc, char **argv)
{
- FILE *file = fopen(uploadthis, "rb");
+ FILE *file = fopen(argv[1], "rb");
CURLcode result;
- /* set callback to use */
- curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ /* set callback to use */
+ curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
- /* pass in suitable argument to callback */
- curl_easy_setopt(curl, CURLOPT_READDATA, (void *)file);
+ /* pass in suitable argument to callback */
+ curl_easy_setopt(curl, CURLOPT_READDATA, (void *)file);
- result = curl_easy_perform(curl);
+ result = curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-curl = curl_easy_init();
-if(curl) {
- /* pass in the URL from an external source */
- curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
+int main(int argc, char **argv)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ /* pass in the URL from an external source */
+ curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
- /* only allow redirects to HTTP and HTTPS URLs */
- curl_easy_setopt(curl, CURLOPT_REDIR_PROTOCOLS,
- CURLPROTO_HTTP | CURLPROTO_HTTPS);
+ /* only allow redirects to HTTP and HTTPS URLs */
+ curl_easy_setopt(curl, CURLOPT_REDIR_PROTOCOLS,
+ CURLPROTO_HTTP | CURLPROTO_HTTPS);
- /* Perform the request */
- curl_easy_perform(curl);
+ /* Perform the request */
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-curl = curl_easy_init();
-if(curl) {
- /* pass in the URL from an external source */
- curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
+int main(int argc, char **argv)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ /* pass in the URL from an external source */
+ curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
- /* only allow redirects to HTTP and HTTPS URLs */
- curl_easy_setopt(curl, CURLOPT_REDIR_PROTOCOLS_STR, "http,https");
+ /* only allow redirects to HTTP and HTTPS URLs */
+ curl_easy_setopt(curl, CURLOPT_REDIR_PROTOCOLS_STR, "http,https");
- /* Perform the request */
- curl_easy_perform(curl);
+ /* Perform the request */
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ 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.com/aboutme.html");
+ /* 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);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP
.SH EXAMPLE
.nf
-curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/*");
- curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "OPTIONS");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/*");
+ curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "OPTIONS");
- /* issue an OPTIONS * request (no leading slash) */
- curl_easy_setopt(curl, CURLOPT_REQUEST_TARGET, "*");
+ /* issue an OPTIONS * request (no leading slash) */
+ curl_easy_setopt(curl, CURLOPT_REQUEST_TARGET, "*");
- /* Perform the request */
- curl_easy_perform(curl);
+ /* Perform the request */
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl;
-struct curl_slist *host = NULL;
-host = curl_slist_append(NULL, "example.com:443:127.0.0.1");
+int main(void)
+{
+ CURL *curl;
+ struct curl_slist *host = NULL;
+ host = curl_slist_append(NULL, "example.com:443:127.0.0.1");
-curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_RESOLVE, host);
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_RESOLVE, host);
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- curl_easy_perform(curl);
+ curl_easy_perform(curl);
- /* always cleanup */
- curl_easy_cleanup(curl);
-}
+ /* always cleanup */
+ curl_easy_cleanup(curl);
+ }
-curl_slist_free_all(host);
+ curl_slist_free_all(host);
+}
.fi
.SH AVAILABILITY
Added in 7.21.3. Removal support added in 7.42.0.
return 0;
}
-CURL *curl = curl_easy_init();
-if(curl) {
- 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);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ 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);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-static int resolver_start_cb(void *resolver_state, void *reserved,
- void *userdata)
+static int start_cb(void *resolver_state, void *reserved,
+ void *userdata)
{
(void)reserved;
printf("Received resolver_state=%p userdata=%p\\n",
return 0;
}
-CURL *curl = curl_easy_init();
-if(curl) {
- 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);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ 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);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP, FTP, SFTP, FILE
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ long size_of_file;
- /* resume upload at byte index 200 */
- curl_easy_setopt(curl, CURLOPT_RESUME_FROM, 200L);
+ curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com");
- /* ask for upload */
- curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
+ /* resume upload at byte index 200 */
+ curl_easy_setopt(curl, CURLOPT_RESUME_FROM, 200L);
- /* set total data amount to expect */
- curl_easy_setopt(curl, CURLOPT_INFILESIZE, size_of_file);
+ /* ask for upload */
+ curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
- /* Perform the request */
- curl_easy_perform(curl);
+ /* set total data amount to expect */
+ curl_easy_setopt(curl, CURLOPT_INFILESIZE, size_of_file);
+
+ /* Perform the request */
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP, FTP, SFTP, FILE
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_off_t resume_position = GET_IT_SOMEHOW;
- curl_off_t file_size = GET_IT_SOMEHOW_AS_WELL;
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_off_t resume_position; /* get it somehow */
+ curl_off_t file_size; /* get it somehow as well */
- curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com");
+ curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com");
- /* resuming upload at this position, possibly beyond 2GB */
- curl_easy_setopt(curl, CURLOPT_RESUME_FROM_LARGE, resume_position);
+ /* resuming upload at this position, possibly beyond 2GB */
+ curl_easy_setopt(curl, CURLOPT_RESUME_FROM_LARGE, resume_position);
- /* ask for upload */
- curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
+ /* ask for upload */
+ curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
- /* set total data amount to expect */
- curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, file_size);
+ /* set total data amount to expect */
+ curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, file_size);
- /* Perform the request */
- curl_easy_perform(curl);
+ /* Perform the request */
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
RTSP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "rtsp://example.com/");
- curl_easy_setopt(curl, CURLOPT_RTSP_CLIENT_CSEQ, 1234L);
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "rtsp://example.com/");
+ curl_easy_setopt(curl, CURLOPT_RTSP_CLIENT_CSEQ, 1234L);
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
RTSP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "rtsp://example.com/");
- /* ask for options! */
- curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_OPTIONS);
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "rtsp://example.com/");
+ /* ask for options! */
+ curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_OPTIONS);
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
RTSP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "rtsp://example.com/");
- curl_easy_setopt(curl, CURLOPT_RTSP_SERVER_CSEQ, 1234L);
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "rtsp://example.com/");
+ curl_easy_setopt(curl, CURLOPT_RTSP_SERVER_CSEQ, 1234L);
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
RTSP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- char *prev_id; /* saved from before somehow */
- curl_easy_setopt(curl, CURLOPT_URL, "rtsp://example.com/");
- curl_easy_setopt(curl, CURLOPT_RTSP_SESSION_ID, prev_id);
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ char *prev_id; /* saved from before somehow */
+ curl_easy_setopt(curl, CURLOPT_URL, "rtsp://example.com/");
+ curl_easy_setopt(curl, CURLOPT_RTSP_SESSION_ID, prev_id);
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
RTSP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- char *prev_id; /* saved from before somehow */
- curl_easy_setopt(curl, CURLOPT_URL, "rtsp://example.com/");
- curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI,
- "rtsp://foo.example.com/twister/video");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "rtsp://example.com/");
+ curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI,
+ "rtsp://foo.example.com/twister/video");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
RTSP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "rtsp://example.com/");
- curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
- curl_easy_setopt(curl, CURLOPT_RTSP_TRANSPORT,
- "RTP/AVP;unicast;client_port=4588-4589");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "rtsp://example.com/");
+ curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
+ curl_easy_setopt(curl, CURLOPT_RTSP_TRANSPORT,
+ "RTP/AVP;unicast;client_port=4588-4589");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
IMAP, LDAP, POP3 and SMTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "imap://example.com/");
- curl_easy_setopt(curl, CURLOPT_USERNAME, "Kurt");
- curl_easy_setopt(curl, CURLOPT_PASSWORD, "xipj3plmq");
- curl_easy_setopt(curl, CURLOPT_SASL_AUTHZID, "Ursel");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "imap://example.com/");
+ curl_easy_setopt(curl, CURLOPT_USERNAME, "Kurt");
+ curl_easy_setopt(curl, CURLOPT_PASSWORD, "xipj3plmq");
+ curl_easy_setopt(curl, CURLOPT_SASL_AUTHZID, "Ursel");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
IMAP, POP3 and SMTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "smtp://example.com/");
- curl_easy_setopt(curl, CURLOPT_SASL_IR, 1L);
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "smtp://example.com/");
+ curl_easy_setopt(curl, CURLOPT_SASL_IR, 1L);
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP, FTP, SFTP
.SH EXAMPLE
.nf
+#include <unistd.h> /* for lseek() */
+
+struct data {
+ int our_fd;
+};
+
static int seek_cb(void *clientp, curl_off_t offset, int origin)
{
struct data *d = (struct data *)clientp;
return CURL_SEEKFUNC_OK;
}
+int main(void)
{
struct data seek_data;
- curl_easy_setopt(CURL *handle, CURLOPT_SEEKFUNCTION, seek_cb);
- curl_easy_setopt(CURL *handle, CURLOPT_SEEKDATA, &seek_data);
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_SEEKFUNCTION, seek_cb);
+ curl_easy_setopt(curl, CURLOPT_SEEKDATA, &seek_data);
+ }
}
.fi
.SH AVAILABILITY
HTTP, FTP, SFTP
.SH EXAMPLE
.nf
+#include <unistd.h> /* for lseek */
+
+struct data {
+ int our_fd;
+};
static int seek_cb(void *clientp, curl_off_t offset, int origin)
{
struct data *d = (struct data *)clientp;
- lseek(our_fd, offset, origin);
+ lseek(d->our_fd, offset, origin);
return CURL_SEEKFUNC_OK;
}
+int main(void)
{
struct data seek_data;
- curl_easy_setopt(CURL *handle, CURLOPT_SEEKFUNCTION, seek_cb);
- curl_easy_setopt(CURL *handle, CURLOPT_SEEKDATA, &seek_data);
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_SEEKFUNCTION, seek_cb);
+ curl_easy_setopt(curl, CURLOPT_SEEKDATA, &seek_data);
+ }
}
.fi
.SH AVAILABILITY
FTP, IMAP, POP3, SMTP, and SSH
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/slow.txt");
- /* wait no more than 23 seconds */
- curl_easy_setopt(curl, CURLOPT_SERVER_RESPONSE_TIMEOUT, 23L);
- ret = curl_easy_perform(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/slow.txt");
+ /* wait no more than 23 seconds */
+ curl_easy_setopt(curl, CURLOPT_SERVER_RESPONSE_TIMEOUT, 23L);
+ res = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP, FTP, IMAP, LDAP, POP3 and SMTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode ret;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_SERVICE_NAME, "custom");
- ret = curl_easy_perform(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode ret;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_SERVICE_NAME, "custom");
+ ret = curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-CURL *curl2 = curl_easy_init(); /* a second handle */
-if(curl) {
- CURLSH *shobject = curl_share_init();
- curl_share_setopt(shobject, CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ CURL *curl2 = curl_easy_init(); /* a second handle */
+ if(curl) {
+ CURLcode res;
+ CURLSH *shobject = curl_share_init();
+ curl_share_setopt(shobject, CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE);
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "");
- curl_easy_setopt(curl, CURLOPT_SHARE, shobject);
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "");
+ curl_easy_setopt(curl, CURLOPT_SHARE, shobject);
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
- /* the second handle shares cookies from the first */
- curl_easy_setopt(curl2, CURLOPT_URL, "https://example.com/second");
- curl_easy_setopt(curl2, CURLOPT_COOKIEFILE, "");
- curl_easy_setopt(curl2, CURLOPT_SHARE, shobject);
- ret = curl_easy_perform(curl2);
- curl_easy_cleanup(curl2);
+ /* the second handle shares cookies from the first */
+ curl_easy_setopt(curl2, CURLOPT_URL, "https://example.com/second");
+ curl_easy_setopt(curl2, CURLOPT_COOKIEFILE, "");
+ curl_easy_setopt(curl2, CURLOPT_SHARE, shobject);
+ res = curl_easy_perform(curl2);
+ curl_easy_cleanup(curl2);
- curl_share_cleanup(shobject);
+ curl_share_cleanup(shobject);
+ }
}
.fi
.SH AVAILABILITY
curlsocktype purpose)
{
int val = *(int *)clientp;
- setsockopt(curldfd, SOL_SOCKET, SO_RCVBUF, (const char *)&val, sizeof(val));
+ setsockopt((int)curlfd, SOL_SOCKET, SO_RCVBUF,
+ (const char *)&val, sizeof(val));
return CURL_SOCKOPT_OK;
}
-curl = curl_easy_init();
-if(curl) {
- int recvbuffersize = 256 * 1024;
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ int recvbuffersize = 256 * 1024;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- /* call this function to set options for the socket */
- curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockopt_callback);
- curl_easy_setopt(curl, CURLOPT_SOCKOPTDATA, &recvbuffersize);
+ /* call this function to set options for the socket */
+ curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockopt_callback);
+ curl_easy_setopt(curl, CURLOPT_SOCKOPTDATA, &recvbuffersize);
- res = curl_easy_perform(curl);
+ res = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
return CURL_SOCKOPT_ALREADY_CONNECTED;
}
-curl = curl_easy_init();
-if(curl) {
- /* libcurl thinks that you connect to the host
- * and port that you specify in the URL option. */
- curl_easy_setopt(curl, CURLOPT_URL, "http://99.99.99.99:9999");
- /* call this function to get a socket */
- curl_easy_setopt(curl, CURLOPT_OPENSOCKETFUNCTION, opensocket);
- curl_easy_setopt(curl, CURLOPT_OPENSOCKETDATA, &sockfd);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ int sockfd; /* our custom file descriptor */
+ /* libcurl thinks that you connect to the host
+ * and port that you specify in the URL option. */
+ curl_easy_setopt(curl, CURLOPT_URL, "http://99.99.99.99:9999");
+ /* call this function to get a socket */
+ curl_easy_setopt(curl, CURLOPT_OPENSOCKETFUNCTION, opensocket);
+ curl_easy_setopt(curl, CURLOPT_OPENSOCKETDATA, &sockfd);
- /* call this function to set options for the socket */
- curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockopt_callback);
+ /* call this function to set options for the socket */
+ curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockopt_callback);
- res = curl_easy_perform(curl);
+ res = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+ curl_easy_cleanup(curl);
+ }
+}
.fi
.SH AVAILABILITY
Added in 7.16.0. The \fICURL_SOCKOPT_ALREADY_CONNECTED\fP return code was
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* request to use a SOCKS5 proxy */
- curl_easy_setopt(curl, CURLOPT_PROXY, "socks5://user:pass@myproxy.com");
+ /* request to use a SOCKS5 proxy */
+ curl_easy_setopt(curl, CURLOPT_PROXY, "socks5://user:pass@myproxy.com");
- /* enable username/password authentication only */
- curl_easy_setopt(curl, CURLOPT_SOCKS5_AUTH, (long)CURLAUTH_BASIC);
+ /* enable username/password authentication only */
+ curl_easy_setopt(curl, CURLOPT_SOCKS5_AUTH, (long)CURLAUTH_BASIC);
- /* Perform the request */
- curl_easy_perform(curl);
+ /* Perform the request */
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
Most
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_PROXY, "socks5://proxy");
- curl_easy_setopt(curl, CURLOPT_SOCKS5_GSSAPI_NEC, 1L);
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_PROXY, "socks5://proxy");
+ curl_easy_setopt(curl, CURLOPT_SOCKS5_GSSAPI_NEC, 1L);
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All network protocols
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_PROXY, "socks5://proxy");
- curl_easy_setopt(curl, CURLOPT_SOCKS5_GSSAPI_SERVICE, "rcmd-special");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_PROXY, "socks5://proxy");
+ curl_easy_setopt(curl, CURLOPT_SOCKS5_GSSAPI_SERVICE, "rcmd-special");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
SFTP and SCP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "sftp://example.com/file");
- curl_easy_setopt(curl, CURLOPT_SSH_AUTH_TYPES,
- CURLSSH_AUTH_PUBLICKEY | CURLSSH_AUTH_KEYBOARD);
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "sftp://example.com/file");
+ curl_easy_setopt(curl, CURLOPT_SSH_AUTH_TYPES,
+ CURLSSH_AUTH_PUBLICKEY | CURLSSH_AUTH_KEYBOARD);
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All SSH based protocols: SCP, SFTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "sftp://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "sftp://example.com");
- /* enable built-in compression */
- curl_easy_setopt(curl, CURLOPT_SSH_COMPRESSION, 1L);
+ /* enable built-in compression */
+ curl_easy_setopt(curl, CURLOPT_SSH_COMPRESSION, 1L);
- /* Perform the request */
- curl_easy_perform(curl);
+ /* Perform the request */
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
SCP and SFTP
.SH EXAMPLE
.nf
-int hostkeycb(void *clientp, /* passed with CURLOPT_SSH_HOSTKEYDATA */
- int keytype, /* CURLKHTYPE */
- const char * key, /* host key to check */
- size_t keylen); /* length of the key */
+struct mine {
+ void *custom;
+};
+
+static int hostkeycb(void *clientp, /* CURLOPT_SSH_HOSTKEYDATA */
+ int keytype, /* CURLKHTYPE */
+ const char *key, /* host key to check */
+ size_t keylen) /* length of the key */
{
/* 'clientp' points to the callback_data struct */
/* investigate the situation and return the correct value */
return CURLKHMATCH_OK;
}
+
+int main(void)
{
- 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 *curl = curl_easy_init();
+ if(curl) {
+ 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);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
SCP and SFTP
.SH EXAMPLE
.nf
+struct mine {
+ void *custom;
+};
+
int hostkeycb(void *clientp, /* passed with CURLOPT_SSH_HOSTKEYDATA */
int keytype, /* CURLKHTYPE */
- const char * key, /* host key to check */
- size_t keylen); /* length of the key */
+ const char *key, /* host key to check */
+ size_t keylen) /* length of the key */
{
/* 'clientp' points to the callback_data struct */
/* investigate the situation and return the correct value */
return CURLKHMATCH_OK;
}
+int main(void)
{
- 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);
+ struct mine callback_data;
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ 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);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
SCP and SFTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "sftp://example.com/file");
- curl_easy_setopt(curl, CURLOPT_SSH_HOST_PUBLIC_KEY_MD5,
- "afe17cd62a0f3b61f1ab9cb22ba269a7");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "sftp://example.com/file");
+ curl_easy_setopt(curl, CURLOPT_SSH_HOST_PUBLIC_KEY_MD5,
+ "afe17cd62a0f3b61f1ab9cb22ba269a7");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
SCP and SFTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "sftp://example.com/file");
- curl_easy_setopt(curl, CURLOPT_SSH_HOST_PUBLIC_KEY_SHA256,
- "NDVkMTQxMGQ1ODdmMjQ3MjczYjAyOTY5MmRkMjVmNDQ=");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "sftp://example.com/file");
+ curl_easy_setopt(curl, CURLOPT_SSH_HOST_PUBLIC_KEY_SHA256,
+ "NDVkMTQxMGQ1ODdmMjQ3MjczYjAyOTY5MmRkMjVmNDQ=");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
SFTP and SCP
.SH EXAMPLE
.nf
+struct mine {
+ void *custom;
+};
static int keycb(CURL *easy,
const struct curl_khkey *knownkey,
const struct curl_khkey *foundkey,
/* investigate the situation and return the correct value */
return CURLKHSTAT_FINE_ADD_TO_FILE;
}
+
+int main(void)
{
- 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 *curl = curl_easy_init();
+ if(curl) {
+ 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);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
SFTP and SCP
.SH EXAMPLE
.nf
+struct mine {
+ void *custom;
+};
+
static int keycb(CURL *easy,
const struct curl_khkey *knownkey,
const struct curl_khkey *foundkey,
/* investigate the situation and return the correct value */
return CURLKHSTAT_FINE_ADD_TO_FILE;
}
+
+int main(void)
{
- 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 *curl = curl_easy_init();
+ if(curl) {
+ 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);
+ curl_easy_perform(curl);
+}
}
.fi
.SH AVAILABILITY
SFTP and SCP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "sftp://example.com/file");
- curl_easy_setopt(curl, CURLOPT_SSH_KNOWNHOSTS,
- "/home/clarkkent/.ssh/known_hosts");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "sftp://example.com/file");
+ curl_easy_setopt(curl, CURLOPT_SSH_KNOWNHOSTS,
+ "/home/clarkkent/.ssh/known_hosts");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
SFTP and SCP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "sftp://example.com/file");
- curl_easy_setopt(curl, CURLOPT_SSH_PRIVATE_KEYFILE,
- "/home/clarkkent/.ssh/id_rsa");
- curl_easy_setopt(curl, CURLOPT_KEYPASSWD, "password");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "sftp://example.com/file");
+ curl_easy_setopt(curl, CURLOPT_SSH_PRIVATE_KEYFILE,
+ "/home/clarkkent/.ssh/id_rsa");
+ curl_easy_setopt(curl, CURLOPT_KEYPASSWD, "password");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
SFTP and SCP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "sftp://example.com/file");
- curl_easy_setopt(curl, CURLOPT_SSH_PUBLIC_KEYFILE,
- "/home/clarkkent/.ssh/id_rsa.pub");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "sftp://example.com/file");
+ curl_easy_setopt(curl, CURLOPT_SSH_PUBLIC_KEYFILE,
+ "/home/clarkkent/.ssh/id_rsa.pub");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_SSLCERT, "client.pem");
- curl_easy_setopt(curl, CURLOPT_SSLKEY, "key.pem");
- curl_easy_setopt(curl, CURLOPT_KEYPASSWD, "s3cret");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_SSLCERT, "client.pem");
+ curl_easy_setopt(curl, CURLOPT_SSLKEY, "key.pem");
+ curl_easy_setopt(curl, CURLOPT_KEYPASSWD, "s3cret");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_SSLCERT, "client.pem");
- curl_easy_setopt(curl, CURLOPT_SSLCERTTYPE, "PEM");
- curl_easy_setopt(curl, CURLOPT_SSLKEY, "key.pem");
- curl_easy_setopt(curl, CURLOPT_KEYPASSWD, "s3cret");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_SSLCERT, "client.pem");
+ curl_easy_setopt(curl, CURLOPT_SSLCERTTYPE, "PEM");
+ curl_easy_setopt(curl, CURLOPT_SSLKEY, "key.pem");
+ curl_easy_setopt(curl, CURLOPT_KEYPASSWD, "s3cret");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- struct curl_blob stblob;
- stblob.data = certificateData;
- stblob.len = filesize;
- stblob.flags = CURL_BLOB_COPY;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_SSLCERT_BLOB, &stblob);
- curl_easy_setopt(curl, CURLOPT_SSLCERTTYPE, "P12");
- curl_easy_setopt(curl, CURLOPT_KEYPASSWD, "s3cret");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+
+extern char *certificateData; /* point to data */
+extern size_t filesize; /* size of data */
+
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ struct curl_blob stblob;
+ stblob.data = certificateData;
+ stblob.len = filesize;
+ stblob.flags = CURL_BLOB_COPY;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_SSLCERT_BLOB, &stblob);
+ curl_easy_setopt(curl, CURLOPT_SSLCERTTYPE, "P12");
+ curl_easy_setopt(curl, CURLOPT_KEYPASSWD, "s3cret");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_SSLENGINE, "dynamic");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_SSLENGINE, "dynamic");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_SSLENGINE, "dynamic");
- curl_easy_setopt(curl, CURLOPT_SSLENGINE_DEFAULT, 1L);
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_SSLENGINE, "dynamic");
+ curl_easy_setopt(curl, CURLOPT_SSLENGINE_DEFAULT, 1L);
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_SSLCERT, "client.pem");
- curl_easy_setopt(curl, CURLOPT_SSLKEY, "key.pem");
- curl_easy_setopt(curl, CURLOPT_KEYPASSWD, "s3cret");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_SSLCERT, "client.pem");
+ curl_easy_setopt(curl, CURLOPT_SSLKEY, "key.pem");
+ curl_easy_setopt(curl, CURLOPT_KEYPASSWD, "s3cret");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_SSLCERT, "client.pem");
- curl_easy_setopt(curl, CURLOPT_SSLKEY, "key.pem");
- curl_easy_setopt(curl, CURLOPT_SSLKEYTYPE, "PEM");
- curl_easy_setopt(curl, CURLOPT_KEYPASSWD, "s3cret");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_SSLCERT, "client.pem");
+ curl_easy_setopt(curl, CURLOPT_SSLKEY, "key.pem");
+ curl_easy_setopt(curl, CURLOPT_SSLKEYTYPE, "PEM");
+ curl_easy_setopt(curl, CURLOPT_KEYPASSWD, "s3cret");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- struct curl_blob blob;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- blob.data = certificateData;
- blob.len = filesize;
- blob.flags = CURL_BLOB_COPY;
- curl_easy_setopt(curl, CURLOPT_SSLCERT_BLOB, &blob);
- curl_easy_setopt(curl, CURLOPT_SSLCERTTYPE, "PEM");
- blob.data = privateKeyData;
- blob.len = privateKeySize;
- curl_easy_setopt(curl, CURLOPT_SSLKEY_BLOB, &blob);
- curl_easy_setopt(curl, CURLOPT_KEYPASSWD, "s3cret");
- curl_easy_setopt(curl, CURLOPT_SSLKEYTYPE, "PEM");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+extern char *certificateData; /* point to cert */
+extern size_t filesize; /* size of cert */
+
+extern char *privateKeyData; /* point to key */
+extern size_t privateKeySize; /* size of key */
+
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ struct curl_blob blob;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ blob.data = certificateData;
+ blob.len = filesize;
+ blob.flags = CURL_BLOB_COPY;
+ curl_easy_setopt(curl, CURLOPT_SSLCERT_BLOB, &blob);
+ curl_easy_setopt(curl, CURLOPT_SSLCERTTYPE, "PEM");
+
+ blob.data = privateKeyData;
+ blob.len = privateKeySize;
+ curl_easy_setopt(curl, CURLOPT_SSLKEY_BLOB, &blob);
+ curl_easy_setopt(curl, CURLOPT_KEYPASSWD, "s3cret");
+ curl_easy_setopt(curl, CURLOPT_SSLKEYTYPE, "PEM");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ 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, (long)CURL_SSLVERSION_TLSv1);
+ /* ask libcurl to use TLS version 1.0 or later */
+ curl_easy_setopt(curl, CURLOPT_SSLVERSION, (long)CURL_SSLVERSION_TLSv1);
- /* Perform the request */
- curl_easy_perform(curl);
+ /* Perform the request */
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
All TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_SSL_CIPHER_LIST, "TLSv1");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_SSL_CIPHER_LIST, "TLSv1");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
* X509 structure that SSL can use
*/
PEM_read_bio_X509(bio, &cert, 0, NULL);
- if(cert == NULL)
+ if(!cert)
printf("PEM_read_bio_X509 failed...\\n");
/* get a pointer to the X509 certificate store (which may be empty) */
int main(void)
{
- CURL * ch;
+ CURL *ch;
CURLcode rv;
char *mypem = /* example CA cert PEM - shortened */
"-----BEGIN CERTIFICATE-----\\n"
* X509 structure that SSL can use
*/
PEM_read_bio_X509(bio, &cert, 0, NULL);
- if(cert == NULL)
+ if(!cert)
printf("PEM_read_bio_X509 failed...\\n");
/* get a pointer to the X509 certificate store (which may be empty) */
int main(void)
{
- CURL * ch;
+ CURL *ch;
CURLcode rv;
char *mypem = /* example CA cert PEM - shortened */
"-----BEGIN CERTIFICATE-----\\n"
HTTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_SSL_EC_CURVES, "X25519:P-521");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_SSL_EC_CURVES, "X25519:P-521");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_SSL_ENABLE_ALPN, 0L);
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_SSL_ENABLE_ALPN, 0L);
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_SSL_ENABLE_NPN, 1L);
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_SSL_ENABLE_NPN, 1L);
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- curl_easy_setopt(curl, CURLOPT_SSL_FALSESTART, 1L);
- curl_easy_perform(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ curl_easy_setopt(curl, CURLOPT_SSL_FALSESTART, 1L);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
All TLS-based protocols
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- /* weaken TLS only for use with silly servers */
- curl_easy_setopt(curl, CURLOPT_SSL_OPTIONS, (long)CURLSSLOPT_ALLOW_BEAST |
- CURLSSLOPT_NO_REVOKE);
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ /* weaken TLS only for use with silly servers */
+ curl_easy_setopt(curl, CURLOPT_SSL_OPTIONS, (long)CURLSSLOPT_ALLOW_BEAST |
+ CURLSSLOPT_NO_REVOKE);
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All TLS-based
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- /* switch off session-id use! */
- curl_easy_setopt(curl, CURLOPT_SSL_SESSIONID_CACHE, 0L);
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ /* switch off session-id use! */
+ curl_easy_setopt(curl, CURLOPT_SSL_SESSIONID_CACHE, 0L);
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ 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);
+ /* Set the default value: strict name check please */
+ curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2L);
- curl_easy_perform(curl);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
All TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ 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);
+ /* Set the default value: strict certificate check please */
+ curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);
- curl_easy_perform(curl);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
All TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- /* ask for OCSP stapling! */
- curl_easy_setopt(curl, CURLOPT_SSL_VERIFYSTATUS, 1L);
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ /* ask for OCSP stapling! */
+ curl_easy_setopt(curl, CURLOPT_SSL_VERIFYSTATUS, 1L);
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-FILE *filep = fopen("dump", "wb");
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- curl_easy_setopt(curl, CURLOPT_STDERR, filep);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ FILE *filep = fopen("dump", "wb");
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ curl_easy_setopt(curl, CURLOPT_STDERR, filep);
- curl_easy_perform(curl);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP/2
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-CURL *curl2 = curl_easy_init(); /* a second handle */
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/one");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ CURL *curl2 = curl_easy_init(); /* a second handle */
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/one");
- /* the second depends on the first */
- curl_easy_setopt(curl2, CURLOPT_URL, "https://example.com/two");
- curl_easy_setopt(curl2, CURLOPT_STREAM_DEPENDS, curl);
+ /* the second depends on the first */
+ curl_easy_setopt(curl2, CURLOPT_URL, "https://example.com/two");
+ curl_easy_setopt(curl2, CURLOPT_STREAM_DEPENDS, curl);
- /* then add both to a multi handle and transfer them! */
+ /* then add both to a multi handle and transfer them! */
+ }
}
.fi
.SH AVAILABILITY
HTTP/2
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-CURL *curl2 = curl_easy_init(); /* a second handle */
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/one");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ CURL *curl2 = curl_easy_init(); /* a second handle */
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/one");
- /* the second depends on the first */
- curl_easy_setopt(curl2, CURLOPT_URL, "https://example.com/two");
- curl_easy_setopt(curl2, CURLOPT_STREAM_DEPENDS_E, curl);
+ /* the second depends on the first */
+ curl_easy_setopt(curl2, CURLOPT_URL, "https://example.com/two");
+ curl_easy_setopt(curl2, CURLOPT_STREAM_DEPENDS_E, curl);
- /* then add both to a multi handle and transfer them! */
+ /* then add both to a multi handle and transfer them! */
+ }
}
.fi
.SH AVAILABILITY
HTTP/2
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-CURL *curl2 = curl_easy_init(); /* a second handle */
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/one");
- curl_easy_setopt(curl, CURLOPT_STREAM_WEIGHT, 10L);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ CURL *curl2 = curl_easy_init(); /* a second handle */
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/one");
+ curl_easy_setopt(curl, CURLOPT_STREAM_WEIGHT, 10L);
- /* the second has twice the weight */
- curl_easy_setopt(curl2, CURLOPT_URL, "https://example.com/two");
- curl_easy_setopt(curl2, CURLOPT_STREAM_WEIGHT, 20L);
+ /* the second has twice the weight */
+ curl_easy_setopt(curl2, CURLOPT_URL, "https://example.com/two");
+ curl_easy_setopt(curl2, CURLOPT_STREAM_WEIGHT, 20L);
- /* then add both to a multi handle and transfer them! */
+ /* then add both to a multi handle and transfer them! */
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- curl_easy_setopt(curl, CURLOPT_HEADER, 1L);
- curl_easy_setopt(curl, CURLOPT_PROXY, "http://foo:3128");
- curl_easy_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, 1L);
- curl_easy_setopt(curl, CURLOPT_SUPPRESS_CONNECT_HEADERS, 1L);
+ curl_easy_setopt(curl, CURLOPT_HEADER, 1L);
+ curl_easy_setopt(curl, CURLOPT_PROXY, "http://foo:3128");
+ curl_easy_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, 1L);
+ curl_easy_setopt(curl, CURLOPT_SUPPRESS_CONNECT_HEADERS, 1L);
- curl_easy_perform(curl);
+ curl_easy_perform(curl);
- /* always cleanup */
- curl_easy_cleanup(curl);
+ /* always cleanup */
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- curl_easy_setopt(curl, CURLOPT_TCP_FASTOPEN, 1L);
- curl_easy_perform(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ curl_easy_setopt(curl, CURLOPT_TCP_FASTOPEN, 1L);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* enable TCP keep-alive for this transfer */
- curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L);
+ /* enable TCP keep-alive for this transfer */
+ curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L);
- /* keep-alive idle time to 120 seconds */
- curl_easy_setopt(curl, CURLOPT_TCP_KEEPIDLE, 120L);
+ /* keep-alive idle time to 120 seconds */
+ curl_easy_setopt(curl, CURLOPT_TCP_KEEPIDLE, 120L);
- /* interval time between keep-alive probes: 60 seconds */
- curl_easy_setopt(curl, CURLOPT_TCP_KEEPINTVL, 60L);
+ /* interval time between keep-alive probes: 60 seconds */
+ curl_easy_setopt(curl, CURLOPT_TCP_KEEPINTVL, 60L);
- curl_easy_perform(curl);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* enable TCP keep-alive for this transfer */
- curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L);
+ /* enable TCP keep-alive for this transfer */
+ curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L);
- /* set keep-alive idle time to 120 seconds */
- curl_easy_setopt(curl, CURLOPT_TCP_KEEPIDLE, 120L);
+ /* set keep-alive idle time to 120 seconds */
+ curl_easy_setopt(curl, CURLOPT_TCP_KEEPIDLE, 120L);
- /* interval time between keep-alive probes: 60 seconds */
- curl_easy_setopt(curl, CURLOPT_TCP_KEEPINTVL, 60L);
+ /* interval time between keep-alive probes: 60 seconds */
+ curl_easy_setopt(curl, CURLOPT_TCP_KEEPINTVL, 60L);
- curl_easy_perform(curl);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* enable TCP keep-alive for this transfer */
- curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L);
+ /* enable TCP keep-alive for this transfer */
+ curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L);
- /* set keep-alive idle time to 120 seconds */
- curl_easy_setopt(curl, CURLOPT_TCP_KEEPIDLE, 120L);
+ /* set keep-alive idle time to 120 seconds */
+ curl_easy_setopt(curl, CURLOPT_TCP_KEEPIDLE, 120L);
- /* interval time between keep-alive probes: 60 seconds */
- curl_easy_setopt(curl, CURLOPT_TCP_KEEPINTVL, 60L);
+ /* interval time between keep-alive probes: 60 seconds */
+ curl_easy_setopt(curl, CURLOPT_TCP_KEEPINTVL, 60L);
- curl_easy_perform(curl);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* leave Nagle enabled */
- curl_easy_setopt(curl, CURLOPT_TCP_NODELAY, 0);
- curl_easy_perform(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ /* leave Nagle enabled */
+ curl_easy_setopt(curl, CURLOPT_TCP_NODELAY, 0);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
TELNET
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- struct curl_slist *options;
- options = curl_slist_append(NULL, "TTTYPE=vt100");
- options = curl_slist_append(options, "USER=foobar");
- curl_easy_setopt(curl, CURLOPT_URL, "telnet://example.com/");
- curl_easy_setopt(curl, CURLOPT_TELNETOPTIONS, options);
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
- curl_slist_free_all(options);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ struct curl_slist *options;
+ options = curl_slist_append(NULL, "TTTYPE=vt100");
+ options = curl_slist_append(options, "USER=foobar");
+ curl_easy_setopt(curl, CURLOPT_URL, "telnet://example.com/");
+ curl_easy_setopt(curl, CURLOPT_TELNETOPTIONS, options);
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ curl_slist_free_all(options);
+ }
}
.fi
.SH AVAILABILITY
TFTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "tftp://example.com/bootimage");
- /* try using larger blocks */
- curl_easy_setopt(curl, CURLOPT_TFTP_BLKSIZE, 2048L);
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "tftp://example.com/bootimage");
+ /* try using larger blocks */
+ curl_easy_setopt(curl, CURLOPT_TFTP_BLKSIZE, 2048L);
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
return fwrite(ptr, size, nmemb, (FILE *)fp);
}
-CURL *curl = curl_easy_init();
-if(curl) {
- FILE *fp = fopen("foo.bin", "wb");
- if(fp) {
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)fp);
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ FILE *fp = fopen("foo.bin", "wb");
+ if(fp) {
+ curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)fp);
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
- curl_easy_setopt(curl, CURLOPT_URL, "tftp://example.com/foo.bin");
+ curl_easy_setopt(curl, CURLOPT_URL, "tftp://example.com/foo.bin");
- /* do not send TFTP options requests */
- curl_easy_setopt(curl, CURLOPT_TFTP_NO_OPTIONS, 1L);
+ /* do not send TFTP options requests */
+ curl_easy_setopt(curl, CURLOPT_TFTP_NO_OPTIONS, 1L);
- /* Perform the request */
- curl_easy_perform(curl);
+ /* Perform the request */
+ curl_easy_perform(curl);
- fclose(fp);
+ fclose(fp);
+ }
+ curl_easy_cleanup(curl);
}
- curl_easy_cleanup(curl);
}
.fi
.SH AVAILABILITY
HTTP, FTP, RTSP, and FILE
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* January 1, 2020 is 1577833200 */
- curl_easy_setopt(curl, CURLOPT_TIMEVALUE, 1577833200L);
+ /* January 1, 2020 is 1577833200 */
+ curl_easy_setopt(curl, CURLOPT_TIMEVALUE, 1577833200L);
- /* If-Modified-Since the above time stamp */
- curl_easy_setopt(curl, CURLOPT_TIMECONDITION,
- (long)CURL_TIMECOND_IFMODSINCE);
+ /* If-Modified-Since the above time stamp */
+ curl_easy_setopt(curl, CURLOPT_TIMECONDITION,
+ (long)CURL_TIMECOND_IFMODSINCE);
- /* Perform the request */
- curl_easy_perform(curl);
+ /* Perform the request */
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* complete within 20 seconds */
- curl_easy_setopt(curl, CURLOPT_TIMEOUT, 20L);
+ /* complete within 20 seconds */
+ curl_easy_setopt(curl, CURLOPT_TIMEOUT, 20L);
- curl_easy_perform(curl);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* complete within 20000 milliseconds */
- curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, 20000L);
+ /* complete within 20000 milliseconds */
+ curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, 20000L);
- curl_easy_perform(curl);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP, FTP, RTSP, and FILE
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* January 1, 2020 is 1577833200 */
- curl_easy_setopt(curl, CURLOPT_TIMEVALUE, 1577833200L);
+ /* January 1, 2020 is 1577833200 */
+ curl_easy_setopt(curl, CURLOPT_TIMEVALUE, 1577833200L);
- /* If-Modified-Since the above time stamp */
- curl_easy_setopt(curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE);
+ /* If-Modified-Since the above time stamp */
+ curl_easy_setopt(curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE);
- /* Perform the request */
- curl_easy_perform(curl);
+ /* Perform the request */
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP, FTP, RTSP, and FILE
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* January 1, 2020 is 1577833200 */
- curl_easy_setopt(curl, CURLOPT_TIMEVALUE_LARGE, (curl_off_t)1577833200);
+ /* January 1, 2020 is 1577833200 */
+ curl_easy_setopt(curl, CURLOPT_TIMEVALUE_LARGE, (curl_off_t)1577833200);
- /* If-Modified-Since the above time stamp */
- curl_easy_setopt(curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE);
+ /* If-Modified-Since the above time stamp */
+ curl_easy_setopt(curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE);
- /* Perform the request */
- curl_easy_perform(curl);
+ /* Perform the request */
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
All TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc.
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_TLS13_CIPHERS,
- "TLS_CHACHA20_POLY1305_SHA256");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_TLS13_CIPHERS,
+ "TLS_CHACHA20_POLY1305_SHA256");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All TLS-based protocols
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_TLSAUTH_TYPE, "SRP");
- curl_easy_setopt(curl, CURLOPT_TLSAUTH_USERNAME, "user");
- curl_easy_setopt(curl, CURLOPT_TLSAUTH_PASSWORD, "secret");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_TLSAUTH_TYPE, "SRP");
+ curl_easy_setopt(curl, CURLOPT_TLSAUTH_USERNAME, "user");
+ curl_easy_setopt(curl, CURLOPT_TLSAUTH_PASSWORD, "secret");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All TLS-based protocols
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_TLSAUTH_TYPE, "SRP");
- curl_easy_setopt(curl, CURLOPT_TLSAUTH_USERNAME, "user");
- curl_easy_setopt(curl, CURLOPT_TLSAUTH_PASSWORD, "secret");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_TLSAUTH_TYPE, "SRP");
+ curl_easy_setopt(curl, CURLOPT_TLSAUTH_USERNAME, "user");
+ curl_easy_setopt(curl, CURLOPT_TLSAUTH_PASSWORD, "secret");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All TLS-based protocols
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
- curl_easy_setopt(curl, CURLOPT_TLSAUTH_TYPE, "SRP");
- curl_easy_setopt(curl, CURLOPT_TLSAUTH_USERNAME, "user");
- curl_easy_setopt(curl, CURLOPT_TLSAUTH_PASSWORD, "secret");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+ curl_easy_setopt(curl, CURLOPT_TLSAUTH_TYPE, "SRP");
+ curl_easy_setopt(curl, CURLOPT_TLSAUTH_USERNAME, "user");
+ curl_easy_setopt(curl, CURLOPT_TLSAUTH_PASSWORD, "secret");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP
.SH EXAMPLE
.nf
-/* Assuming we have a CURL handle in the hndl variable. */
+struct MyData {
+ void *custom;
+};
-struct MyData data;
-
-curl_easy_setopt(hndl, CURLOPT_TRAILERDATA, &data);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ struct MyData data;
+ curl_easy_setopt(curl, CURLOPT_TRAILERDATA, &data);
+ }
+}
.fi
A more complete example can be found in examples/http_trailers.html
FTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/textfile");
- curl_easy_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/textfile");
+ curl_easy_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- curl_easy_setopt(curl, CURLOPT_TRANSFER_ENCODING, 1L);
- curl_easy_perform(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ curl_easy_setopt(curl, CURLOPT_TRANSFER_ENCODING, 1L);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
All protocols except for FILE and FTP are supported in theory. HTTP, IMAP,
POP3 and SMTP should in particular work (including their SSL/TLS variants).
.SH EXAMPLE
-Given that you have an HTTP server running listening on /tmp/httpd.sock, you
-can request an HTTP resource with:
-
.nf
- curl_easy_setopt(curl_handle, CURLOPT_UNIX_SOCKET_PATH, "/tmp/httpd.sock");
- curl_easy_setopt(curl_handle, CURLOPT_URL, "http://localhost/");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_UNIX_SOCKET_PATH, "/tmp/httpd.sock");
+ curl_easy_setopt(curl, CURLOPT_URL, "http://localhost/");
+
+ curl_easy_perform(curl);
+ }
+}
.fi
If you are on Linux and somehow have a need for paths larger than 107 bytes,
-you could use the proc filesystem to bypass the limitation:
+you can use the proc filesystem to bypass the limitation:
.nf
int dirfd = open(long_directory_path_to_socket, O_DIRECTORY | O_RDONLY);
HTTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
- curl_easy_setopt(curl, CURLOPT_UNRESTRICTED_AUTH, 1L);
- curl_easy_perform(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+ curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
+ curl_easy_setopt(curl, CURLOPT_UNRESTRICTED_AUTH, 1L);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- /* Make a connection to an HTTP/2 server. */
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ /* Make a connection to an HTTP/2 server. */
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* Set the interval to 30000ms / 30s */
- curl_easy_setopt(curl, CURLOPT_UPKEEP_INTERVAL_MS, 30000L);
+ /* Set the interval to 30000ms / 30s */
+ curl_easy_setopt(curl, CURLOPT_UPKEEP_INTERVAL_MS, 30000L);
- curl_easy_perform(curl);
+ curl_easy_perform(curl);
- /* Perform more work here. */
+ /* Perform more work here. */
- /* While the connection is being held open, curl_easy_upkeep() can be
- called. If curl_easy_upkeep() is called and the time since the last
- upkeep exceeds the interval, then an HTTP/2 PING is sent. */
- curl_easy_upkeep(curl);
+ /* While the connection is being held open, curl_easy_upkeep() can be
+ called. If curl_easy_upkeep() is called and the time since the last
+ upkeep exceeds the interval, then an HTTP/2 PING is sent. */
+ curl_easy_upkeep(curl);
- /* Perform more work here. */
+ /* Perform more work here. */
- /* always cleanup */
- curl_easy_cleanup(curl);
+ /* always cleanup */
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
Most
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- /* we want to use our own read function */
- curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
+static size_t read_cb(char *ptr, size_t size, size_t nmemb, void *userdata)
+{
+ FILE *src = userdata;
+ /* copy as much data as possible into the 'ptr' buffer, but no more than
+ 'size' * 'nmemb' bytes! */
+ size_t retcode = fread(ptr, size, nmemb, src);
- /* enable uploading */
- curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
+ return retcode;
+}
+
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ FILE *src = fopen("local-file", "r");
+ curl_off_t fsize; /* set this to the size of the input file */
+
+ /* we want to use our own read function */
+ curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_cb);
+
+ /* enable uploading */
+ curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
- /* specify target */
- curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/dir/to/newfile");
+ /* specify target */
+ curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/dir/to/newfile");
- /* now specify which pointer to pass to our callback */
- curl_easy_setopt(curl, CURLOPT_READDATA, hd_src);
+ /* now specify which pointer to pass to our callback */
+ curl_easy_setopt(curl, CURLOPT_READDATA, src);
- /* Set the size of the file to upload */
- curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)fsize);
+ /* Set the size of the file to upload */
+ 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);
+ /* Now run off and do what you have been told! */
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "sftp://example.com/foo.bin");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "sftp://example.com/foo.bin");
- /* ask libcurl to allocate a larger upload buffer */
- curl_easy_setopt(curl, CURLOPT_UPLOAD_BUFFERSIZE, 120000L);
+ /* ask libcurl to allocate a larger upload buffer */
+ curl_easy_setopt(curl, CURLOPT_UPLOAD_BUFFERSIZE, 120000L);
- ret = curl_easy_perform(curl);
+ res = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
-
- curl_easy_perform(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
HTTP, HTTPS
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- curl_easy_setopt(curl, CURLOPT_USERAGENT, "Dark Secret Ninja/1.0");
+ curl_easy_setopt(curl, CURLOPT_USERAGENT, "Dark Secret Ninja/1.0");
- curl_easy_perform(curl);
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
Most
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
- curl_easy_setopt(curl, CURLOPT_USERNAME, "clark");
+ curl_easy_setopt(curl, CURLOPT_USERNAME, "clark");
- ret = curl_easy_perform(curl);
+ res = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
Most
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
- curl_easy_setopt(curl, CURLOPT_USERPWD, "clark:kent");
+ curl_easy_setopt(curl, CURLOPT_USERPWD, "clark:kent");
- ret = curl_easy_perform(curl);
+ res = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
FTP, SMTP, POP3, IMAP, LDAP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/dir/file.ext");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/dir/file.ext");
- /* require use of SSL for this, or fail */
- curl_easy_setopt(curl, CURLOPT_USE_SSL, (long)CURLUSESSL_ALL);
+ /* require use of SSL for this, or fail */
+ curl_easy_setopt(curl, CURLOPT_USE_SSL, (long)CURLUSESSL_ALL);
- /* Perform the request */
- curl_easy_perform(curl);
+ /* Perform the request */
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- /* ask libcurl to show us the verbose output */
- curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
+ /* ask libcurl to show us the verbose output */
+ curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
- /* Perform the request */
- curl_easy_perform(curl);
+ /* Perform the request */
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
This feature is only supported for FTP download.
.SH EXAMPLE
.nf
-/* initialization of easy handle */
-handle = curl_easy_init();
-/* turn on wildcard matching */
-curl_easy_setopt(handle, CURLOPT_WILDCARDMATCH, 1L);
+extern long begin_cb(struct curl_fileinfo *, void *, int);
+extern long end_cb(void *ptr);
-/* callback is called before download of concrete file started */
-curl_easy_setopt(handle, CURLOPT_CHUNK_BGN_FUNCTION, file_is_coming);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ /* turn on wildcard matching */
+ curl_easy_setopt(curl, CURLOPT_WILDCARDMATCH, 1L);
-/* callback is called after data from the file have been transferred */
-curl_easy_setopt(handle, CURLOPT_CHUNK_END_FUNCTION, file_is_downloaded);
+ /* callback is called before download of concrete file started */
+ curl_easy_setopt(curl, CURLOPT_CHUNK_BGN_FUNCTION, begin_cb);
-/* See more on https://curl.se/libcurl/c/ftp-wildcard.html */
+ /* callback is called after data from the file have been transferred */
+ curl_easy_setopt(curl, CURLOPT_CHUNK_END_FUNCTION, end_cb);
+
+ /* See more on https://curl.se/libcurl/c/ftp-wildcard.html */
+ }
+}
.fi
.SH AVAILABILITY
Added in 7.21.0
For all protocols
.SH EXAMPLE
.nf
+#include <stdlib.h> /* for realloc */
+#include <string.h> /* for memcpy */
+
struct memory {
char *response;
size_t size;
struct memory *mem = (struct memory *)clientp;
char *ptr = realloc(mem->response, mem->size + realsize + 1);
- if(ptr == NULL)
+ if(!ptr)
return 0; /* out of memory! */
mem->response = ptr;
return realsize;
}
-struct memory chunk = {0};
-CURLcode res;
-CURL *curl_handle = curl_easy_init();
-
-if (curl_handle)
+int main(void)
{
- /* send all data to this function */
- curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, cb);
+ struct memory chunk = {0};
+ CURLcode res;
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ /* send all data to this function */
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, cb);
- /* we pass our 'chunk' struct to the callback function */
- curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk);
+ /* we pass our 'chunk' struct to the callback function */
+ curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
- /* send a request */
- res = curl_easy_perform(curl_handle);
+ /* send a request */
+ res = curl_easy_perform(curl);
- /* remember to free the buffer */
- free(chunk.response);
+ /* remember to free the buffer */
+ free(chunk.response);
- curl_easy_cleanup(curl_handle);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
WebSocket
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "ws://example.com/");
- /* tell curl we deal with all the WebSocket magic ourselves */
- curl_easy_setopt(curl, CURLOPT_WS_OPTIONS, (long)CURLWS_RAW_MODE);
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "ws://example.com/");
+ /* tell curl we deal with all the WebSocket magic ourselves */
+ curl_easy_setopt(curl, CURLOPT_WS_OPTIONS, (long)CURLWS_RAW_MODE);
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
- struct progress {
- char *private;
- size_t size;
- };
+struct progress {
+ char *private;
+ size_t size;
+};
- static size_t progress_callback(void *clientp,
- curl_off_t dltotal,
- curl_off_t dlnow,
- curl_off_t ultotal,
- curl_off_t ulnow)
- {
- struct memory *progress = (struct progress *)clientp;
+static size_t progress_cb(void *clientp,
+ curl_off_t dltotal,
+ curl_off_t dlnow,
+ curl_off_t ultotal,
+ curl_off_t ulnow)
+{
+ struct progress *memory = clientp;
+ printf("private ptr: %p\\n", memory->private);
+ /* use the values */
- /* use the values */
+ return 0; /* all is good */
+}
- return 0; /* all is good */
- }
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ struct progress data;
- struct progress data;
-
- /* pass struct to callback */
- curl_easy_setopt(curl_handle, CURLOPT_XFERINFODATA, &data);
-
- curl_easy_setopt(curl_handle, CURLOPT_XFERINFOFUNCTION, progress_callback);
+ /* pass struct to callback */
+ curl_easy_setopt(curl, CURLOPT_XFERINFODATA, &data);
+ curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, progress_cb);
+ }
+}
.fi
.SH AVAILABILITY
Added in 7.32.0
All
.SH EXAMPLE
.nf
- struct progress {
- char *private;
- size_t size;
- };
-
- static size_t progress_callback(void *clientp,
- curl_off_t dltotal,
- curl_off_t dlnow,
- curl_off_t ultotal,
- curl_off_t ulnow)
- {
- struct progress *memory = (struct progress *)clientp;
-
- /* use the values */
-
- return 0; /* all is good */
- }
-
- struct progress data;
-
- /* pass struct to callback */
- curl_easy_setopt(curl_handle, CURLOPT_XFERINFODATA, &data);
-
- curl_easy_setopt(curl_handle, CURLOPT_XFERINFOFUNCTION, progress_callback);
+struct progress {
+ char *private;
+ size_t size;
+};
+
+static size_t progress_callback(void *clientp,
+ curl_off_t dltotal,
+ curl_off_t dlnow,
+ curl_off_t ultotal,
+ curl_off_t ulnow)
+{
+ struct progress *memory = clientp;
+ printf("my ptr: %p\\n", memory->private);
+
+ /* use the values */
+
+ return 0; /* all is good */
+}
+
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ struct progress data;
+
+ /* pass struct to callback */
+ curl_easy_setopt(curl, CURLOPT_XFERINFODATA, &data);
+
+ curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, progress_callback);
+ }
+}
.fi
.SH AVAILABILITY
Added in 7.32.0. This callback replaces \fICURLOPT_PROGRESSFUNCTION(3)\fP
HTTP, IMAP, LDAP, POP3 and SMTP
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- curl_easy_setopt(curl, CURLOPT_URL, "pop3://example.com/");
- curl_easy_setopt(curl, CURLOPT_XOAUTH2_BEARER, "1ab9cb22ba269a7");
- ret = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, "pop3://example.com/");
+ curl_easy_setopt(curl, CURLOPT_XOAUTH2_BEARER, "1ab9cb22ba269a7");
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
}
.fi
.SH AVAILABILITY
All
.SH EXAMPLE
.nf
+extern void mutex_lock(CURL *handle, curl_lock_data data,
+ curl_lock_access access, void *clientp);
+
+int main(void)
+{
CURLSHcode sh;
- share = curl_share_init();
+ CURLSH *share = curl_share_init();
sh = curl_share_setopt(share, CURLSHOPT_LOCKFUNC, mutex_lock);
if(sh)
printf("Error: %s\\n", curl_share_strerror(sh));
+}
.fi
.SH AVAILABILITY
Added in 7.10
All
.SH EXAMPLE
.nf
+int main(void)
+{
CURLSHcode sh;
- share = curl_share_init();
+ CURLSH *share = curl_share_init();
sh = curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE);
if(sh)
printf("Error: %s\\n", curl_share_strerror(sh));
+}
.fi
.SH AVAILABILITY
Added in 7.10
All
.SH EXAMPLE
.nf
+extern void mutex_unlock(CURL *, curl_lock_data, void *);
+
+int main(void)
+{
CURLSHcode sh;
- share = curl_share_init();
+ CURLSH *share = curl_share_init();
sh = curl_share_setopt(share, CURLSHOPT_UNLOCKFUNC, mutex_unlock);
if(sh)
printf("Error: %s\\n", curl_share_strerror(sh));
+}
.fi
.SH AVAILABILITY
Added in 7.10
All
.SH EXAMPLE
.nf
+int main(void)
+{
CURLSHcode sh;
- share = curl_share_init();
+ CURLSH *share = curl_share_init();
sh = curl_share_setopt(share, CURLSHOPT_UNSHARE, CURL_LOCK_DATA_COOKIE);
if(sh)
printf("Error: %s\\n", curl_share_strerror(sh));
+}
.fi
.SH AVAILABILITY
Added in 7.10
All
.SH EXAMPLE
.nf
+struct secrets {
+ void *custom;
+};
+
+int main(void)
+{
CURLSHcode sh;
struct secrets private_stuff;
- share = curl_share_init();
+ CURLSH *share = curl_share_init();
sh = curl_share_setopt(share, CURLSHOPT_USERDATA, &private_stuff);
if(sh)
printf("Error: %s\\n", curl_share_strerror(sh));
+}
.fi
.SH AVAILABILITY
Added in 7.10
#include "options.h"
#include "header.h"
#include "websockets.h"
+#include "mprintf.h"
/* the typechecker doesn't work in C++ (yet) */
#if defined(__GNUC__) && defined(__GNUC_MINOR__) && \