c ++ libcurl json rest
Estou tentando baixar um arquivo json de uma página da Web REST em C ++ com libcurl. O código a seguir funciona se eu for para a página da Web, mas ele não será baixado se eu tentar acessar o json ....
Acho que deve ser uma solução fácil, mas não consigo encontrar nenhuma referência a isso ...
Se eu for para a página da Web, ele abrirá o json, mas esse código retornará apenas texto / html; charset = utf-8
??????????
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, &ct);
if((CURLE_OK == res) && ct)
printf("We received Content-Type: %s\n", ct);
}
}
/* always cleanup */
curl_easy_cleanup(curl);