Search…
--libcurl
We actively encourage users to first try out the transfer they want to do with the curl command-line tool, and once it works roughly the way you want it to, you append the --libcurl [filename] option to the command line and run it again.
The --libcurl command-line option will create a C program in the provided file name. That C program is an application that uses libcurl to run the transfer you just had the curl command-line tool do. There are some exceptions and it is not always a 100% match, but you will find that it can serve as an excellent inspiration source for what libcurl options you want or can use and what additional arguments to provide to them.
If you specify the filename as a single dash, as in --libcurl - you will get the program written to stdout instead of a file.
As an example, we run a command to just get http://example.com:
1
curl http://example.com --libcurl example.c
Copied!
This creates example.c in the current directory, looking similar to this:
1
/********* Sample code generated by the curl command-line tool **********
2
* All curl_easy_setopt() options are documented at:
3
* https://curl.se/libcurl/c/curl_easy_setopt.html
4
************************************************************************/
5
#include <curl/curl.h>
6
7
int main(int argc, char *argv[])
8
{
9
CURLcode ret;
10
CURL *hnd;
11
12
hnd = curl_easy_init();
13
curl_easy_setopt(hnd, CURLOPT_URL, "http://example.com");
14
curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 1L);
15
curl_easy_setopt(hnd, CURLOPT_USERAGENT, "curl/7.45.0");
16
curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L);
17
curl_easy_setopt(hnd, CURLOPT_SSH_KNOWNHOSTS, "/home/daniel/.ssh/known_hosts");
18
curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L);
19
20
/* Here is a list of options the curl code used that cannot get generated
21
as source easily. You may select to either not use them or implement
22
them yourself.
23
24
CURLOPT_WRITEDATA set to a objectpointer
25
CURLOPT_WRITEFUNCTION set to a functionpointer
26
CURLOPT_READDATA set to a objectpointer
27
CURLOPT_READFUNCTION set to a functionpointer
28
CURLOPT_SEEKDATA set to a objectpointer
29
CURLOPT_SEEKFUNCTION set to a functionpointer
30
CURLOPT_ERRORBUFFER set to a objectpointer
31
CURLOPT_STDERR set to a objectpointer
32
CURLOPT_HEADERFUNCTION set to a functionpointer
33
CURLOPT_HEADERDATA set to a objectpointer
34
35
*/
36
37
ret = curl_easy_perform(hnd);
38
39
curl_easy_cleanup(hnd);
40
hnd = NULL;
41
42
return (int)ret;
43
}
44
/**** End of sample code ****/
Copied!
Last modified 1yr ago
Export as PDF
Copy link
Edit on GitHub