From http://curl.haxx.se/libcurl/c/libcurl-tutorial.html:
So, you write your own function that matches this prototype:
size_t write_data(void *buffer, size_t size, size_t nmemb, void *userp);
You tell libcurl to pass all data to this function by issuing a function similar to this:
curl_easy_setopt(easyhandle, CURLOPT_WRITEFUNCTION, write_data);
Can someone explain what the arguments size
and nmemb
stand for? Is size
the number of characters in the response? Then what is nmemb
?
This is designed for the function such as: size_t fwrite(const void* buffer, size_t size, size_t count, FILE* stream);
FILE* out = fopen("out.html", "w");
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)out);
curl_easy_setopt(easyhandle, CURLOPT_WRITEFUNCTION, fwrite);
So we need not to add more code for fwrite
as it is!
Apparently "size is the size of one data item, nmemb is the number of data items". My guess is that it's some internal implementation detail. The real data size = size * nmemb.
The documentation for the callback function: https://curl.haxx.se/libcurl/c/CURLOPT_WRITEFUNCTION.html
Example code:
https://github.com/curl/curl/blob/master/docs/examples/getinmemory.c
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With