我想使用Curlopt_header函数 效果很好
如何防止该功能在屏幕上打印?
我找到了写功能的解决方案,
lib curl in c++ disable printing
但是它不适用于标头功能
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());
}
答案 0 :(得分: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);