title: c++ libcurl json rest
body: <p>I am trying to download a json file from a REST webpage in C++ with libcurl.
  The following code works if I go to the webpage but it doesnt download if I try to access the json ....</p>
  
  <p>I think it should be an easy fix but I cant find any reference to this ...</p>
  
  <p>If I go to webpage it opens the json but this code only returns  text/html; charset=utf-8</p>
  
  <p>??????????</p>
  
  <pre><code>CURL *curl;
  CURLcode res;
      struct curl_slist *headers=NULL; // init to NULL is important 
      headers = curl_slist_append(headers, "Accept: application/json");   
  
  curl = curl_easy_init();
  if(curl) {
  
      curl_easy_setopt(curl, CURLOPT_URL, "http://web.com/api/json/123");
              curl_easy_setopt(curl, CURLOPT_HTTPGET,1);
      curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
      //curl_easy_setopt(curl, CURLOPT_URL, "http://web.com/123.html");//this works!!!
      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);
      }
  }
  /* always cleanup */ 
  curl_easy_cleanup(curl);
  </code></pre>