开发者

hide curl_easy_perform

How ca开发者_StackOverflow中文版n I hide curl_easy_perform output (in a shell)?

This is in regards to a C application.


Use CURLOPT_NOBODY in curl_easy_setopt(). Example:

 ...

CURL *curl;
CURLcode statusCode;

curl = curl_easy_init();
if(curl){
    curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.com/");
    //CURLOPT_NOBODY does the trick
    curl_easy_setopt(curl, CURLOPT_NOBODY, 1);
    curl_easy_perform(curl);

 ...

Link to docs: http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTNOBODY


Set the CURLOPT_WRITEFUNCTION and/or CURLOPT_WRITEDATA options:

FILE *f = fopen("target.txt", "wb");
curl_easy_setopt(handle, CURLOPT_WRITEDATA, f);

By default, libcurl writes output to stdout. When you override this (which is what almost any application will do), it will write to another file or to pass chunks of output to a callback. See the documentation for CURLOPT_WRITEFUNCTION for more details.


As Joey said, CURLOPT_WRITEFUNCTION will allow you to completely disregard all output. Just set up a callback that does absolutely nothing if you want the data to just go away, without being written to any file descriptor.

For instance,

/* Never writes anything, just returns the size presented */
size_t my_dummy_write(char *ptr, size_t size, size_t nmemb, void *userdata)
{
   return size * nmemb;
}

Then in your options:

curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, &my_dummy_write);

Or, point the file handle at a NULL device (a lot easier).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜