My C++ program currently invokes curl through a pipe (popen(\"curl ...\")
) to POST a file of JSON data to a web server. This has obvious performance limitations due
You can use CURLOPT_POSTFIELDS
:
CURL *curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/api/endpoint");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "{\"hi\" : \"there\"}");
curl_easy_perform(curl);
Since CURLOPT_POSTFIELDS
does not modify the payload in any way, it is very convenient for POSTing JSON data. Also note that, when CURLOPT_POSTFIELDS
is supplied, it automatically enables CURLOPT_POST
so there is no need to provide CURLOPT_POST
in the request.