我想使用 Curlopt_headerfunction 这很好用
如何防止功能在屏幕上打印?
我找到了 write 函数的解决方案,
但它不适用于标头功能
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());
}