title: How do I POST a buffer of JSON using libcurl?
body: <p>My C++ program currently invokes curl through a pipe (<code>popen("curl ...")</code>) to POST a file of JSON data to a web server. This has obvious performance limitations due to the need to save the JSON to a file and invoke curl in a subshell. I'd like to rewrite it to use libcurl, but it is not clear to me how to do this. The command line I pass to <code>popen()</code> is:</p>
  
  <pre><code>curl -s -S -D /dev/null -H "Content-Type: application/json" -X POST -d file-of-json http://server/handler.php
  </code></pre>
  
  <p>The JSON data (about 3K) is sitting in a buffer in RAM before I need to post it. I was expecting to use libcurl's <code>CURLOPT_READFUNCTION</code> to spool the buffer to libcurl (but I am open to alternatives), and <code>CURLOPT_WRITEFUNCTION</code> to capture the server's reply, similar to how I read the reply from popen's pipe.</p>
  
  <p>All that seems straightforward. What is confusing is which combination of <code>CURLOPT_POST</code>, <code>CURLOPT_HTTPPOST</code>, <code>CURLOPT_POSTFIELDS</code>, <code>CURLOPT_HTTPHEADER</code> I need. I have read many posts on this subject (no pun intended), and none exactly match my scenario. Any suggestions?</p>
  
  <p>[Note that I normally do not have any URL-encoded form fields, like this: <code>http://server/handler.php?I=do&amp;not=use&amp;these=in&amp;my=query</code>]</p>