0

我想使用 Curlopt_headerfunction 这很好用

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

我找到了 write 函数的解决方案,

c ++中的lib curl禁用打印

但它不适用于标头功能

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());

}
4

1 回答 1

0

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

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);
于 2019-07-29T11:05:24.330 回答