我有以下用C ++填充的数据类型
std::vector<uint8_t> bytes;
使用libcurl,如何将其发布到HTTP端点?
尝试了以下代码,但我认为它不能使用我的帖子数据
CURL *curl;
CURLcode res;
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://1.2.3.4:9002/multicastdataclient-message");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, &bytes);
res = curl_easy_perform(curl);
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
curl_easy_cleanup(curl);
}
答案 0 :(得分:0)
基于所有评论,以下代码有效!
CURL *卷曲; CURLcode res;
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://1.2.3.4:9002/message");
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, bytes.size());
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, bytes.data());
res = curl_easy_perform(curl);
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
curl_easy_cleanup(curl);
}
else
{
DBG("curl empty !!");
}