【问题标题】:How to disable cout for the curlopt_headerfunction, prevent printing on screen如何禁用 curlopt_header 函数的 cout,防止在屏幕上打印
【发布时间】:2019-07-18 07:18:00
【问题描述】:

我想使用 Curlopt_header 函数 这很好用

如何防止该功能在屏幕上打印?

我已经找到了写函数的解决方案,

lib curl in c++ disable printing

但它不适用于header函数

static size_t header_callback(char *buffer, size_t size,size_t nitems, void *userdata)
{
  // received header is nitems * size long in 'buffer' NOT ZERO TERMINATED
  // 'userdata' is set with CURLOPT_HEADERDATA
  return nitems * size;
}

void RecieveData{
curl = curl_easy_init();
std::string sData;
if (curl){
curl_easy_setopt(curl, CURLOPT_URL, Resource.c_str());
curl_easy_setopt (curl, CURLOPT_VERBOSE, 0L); //0 disable messages
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, false);
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, header_callback);
curl_easy_setopt(curl, CURLOPT_HEADERDATA, false);
curl_easy_setopt(curl, CURLOPT_HEADERDATA, &sData);
res = curl_easy_perform(curl);
}
printf("Received data %s\r\n", sData.c_str());

}

【问题讨论】:

    标签: c++ libcurl cout disable


    【解决方案1】:

    我想你的意思是你想阻止响应体获得输出?然后添加如下内容:

    static size_t write_cb(char *d, size_t n, size_t l, void *p)
    {
       /* take care of the data here, ignored in this example */
      (void)d;
      (void)p;
      return n*l;
    }
    
    /* tell curl to use this callback to deliver ("write") data */
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_cb);
    

    【讨论】:

      猜你喜欢
      • 2010-10-01
      • 1970-01-01
      • 2016-03-30
      • 2022-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-05
      相关资源
      最近更新 更多