我如何在不向 /dev/null 馈送的情况下使 libcurl 的输出静音?

How would i silence the output of libcurl without feeding to /dev/null?

我该如何停止:

* Trying <ip address>...
* TCP_NODELAY set
* Connected to test.com (<ip address>) port 443 (#0)
> POST /test/ HTTP/1.1 

在 cmd 输出中显示?

这些选项应该有所帮助:

curl_easy_setopt(handle, CURLOPT_NOPROGRESS, 1);
curl_easy_setopt(handle, CURLOPT_VERBOSE, 0);

如果不需要返回的document/file,定义一个write_callback回调函数:

static size_t write_callback(char *ptr, size_t size, size_t nmemb, void *userdata);
    /*
    size_t written = fwrite(ptr, size, nmemb, static_cast<FILE*>(userdata));
    return written;
    */
    return size*nmemb;
}

并设置选项以将输出重定向到您的回调函数:

curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, write_callback);
curl_easy_setopt(handle, CURLOPT_WRITEDATA, nullptr);