title: trying to figure out how to send json data via lib curl in c
body: <p>I'm trying to figure it out hoy to send json data to a web service.
  json.phph y just a php who prints all the $_REQUEST send to the script. but in hehe end i receive nothing,, i tried sending the form in urlenc format and just normal data D:
  im running out of ideas how this can be done.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  #include &lt;curl/curl.h&gt;
  
  int main(int argc, char *argv[]) 
  {
    CURL *curl;
    CURLcode res;
  
    struct curl_httppost *formpost=NULL;
    struct curl_httppost *lastptr=NULL;
    struct curl_slist *headerlist=NULL;
    static const char buf[] = "Content-Type: application/json";
  
    curl_global_init(CURL_GLOBAL_ALL);
  /* 
        curl_formadd(&amp;formpost,
                 &amp;lastptr,
                 CURLFORM_COPYNAME, "json", 
                 CURLFORM_COPYCONTENTS, "reactantsJSON={\"O=O\":{\"N\":1}}&amp;productsJSON=    [\"O=O\",\"[O]\"]&amp;temperature=2273.15&amp;pressure=101.325",
                 CURLFORM_END);
  */
    curl = curl_easy_init();
    /* initalize custom header list (stating that Expect: 100-continue is not
   *      wanted */ 
    headerlist = curl_slist_append(headerlist, buf); 
    if(curl) {
      /* what URL that receives this POST */ 
      curl_easy_setopt(curl, CURLOPT_URL, "http://127.0.0.1/json.php");
        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
      curl_easy_setopt(curl,CURLOPT_POST,1);
      curl_easy_setopt(curl,CURLOPT_POSTFIELDS,     "reactantsJSON%3d%7b%22O%3dO%22%3a%7b%22N%22%3a1%7d%7d%26productsJSON%3d%5b%22O%3dO%22%2c%22%5bO%5d%22%5d%26temperature%3d2273.15%26pressure%3d101.325"  );
  //    curl_easy_setopt(curl,CURLOPT_POSTFIELDS, "reactantsJSON={\"O=O\":    {\"N\":1}}&amp;productsJSON=[\"O=O\",\"[O]\"]&amp;temperature=2273.15&amp;pressure=101.325"  );
   //   if ( (argc == 2) &amp;&amp; (!strcmp(argv[1], "noexpectheader")) )
        /* only disable 100-continue header if explicitly requested */ 
      curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
      res = curl_easy_perform(curl);
  
      /* always cleanup */ 
       curl_easy_cleanup(curl);
  
      /* then cleanup the formpost chain */ 
      curl_formfree(formpost);
      /* free slist */ 
      curl_slist_free_all (headerlist);
    }
    return 0;
  }
  </code></pre>