title: JSON request using cURL in C++
body: <p>I have following command in cURL, this works fine in terminal.</p>
  
  <p><code>curl --insecure -X POST --data "username=testuser&amp;password=12345" https://m360-prototype.herokuapp.com/sessions.json</code></p>
  
  <p>This json api sends a few parameters like these-- <code>"status":{"code":200,"message":"OK"}</code></p>
  
  <p>Now i want my c++ program to execute it. I have set up and used cURL before for ftp upload and download from ftp examples. But i did not find any example to do this.</p>
  
  <p>I want to know how can i pass username and password parameters to the json api, and get response from it.</p>
  
  <p>Here is what i have tried in some code I found on web, it didnt work.</p>
  
  <pre><code>struct curl_slist *headers=NULL; // init to NULL is important
  
  headers = curl_slist_append(headers, "Accept: application/json");
  headers = curl_slist_append(headers, "Content-Type: application/json");
  headers = curl_slist_append(headers, "charsets: utf-8");
  
  curl = curl_easy_init();
  if(curl) {
      curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
      curl_easy_setopt(curl, CURLOPT_URL, "https://m360-prototype.herokuapp.com/sessions.json");
      curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "username=testuser&amp;password=12345");
  
      curl_easy_setopt(curl, CURLOPT_HTTPGET,1);
      curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
      res = curl_easy_perform(curl);
  
      if(CURLE_OK == res) {
          char *ct;
          /* ask for the content-type */
          res = curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &amp;ct);
          if((CURLE_OK == res) &amp;&amp; ct)
              printf("We received Content-Type: %s\n", ct);
      }
  }
  </code></pre>
  
  <p>How do i get response from the web? i know it will be in the form of strings, and i am capable enough to parse it. </p>
  
  <p>I am looking up all the params (--insecure, -X, POST, --data)passed to the curl command executed on terminal, so as to get little idea about what i have to do.</p>
  
  <p>I am a graphics programmer :) not so good with web services.
  I'd appreciate any help.</p>