How to do HEAD instead of GET with libcurl?

2

Is there a way to make libcurl not download the url but only the HTTP headers?

Depending on them I would like to decide if my program downloads the url .

    
asked by sanandresm 20.02.2016 в 01:22
source

1 answer

1

To request the HEAD of a url in libcurl you have to set the option CURLOPT_NOBODY = 1L

CURL *curl = curl_easy_init();
if(curl) {
  CURLcode res;
  curl_easy_setopt(curl, CURLOPT_URL, "http://ejemplo.com");

  // esto hace que se utilize el verbo HEAD en lugar de GET
  curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);

  res = curl_easy_perform(curl);

  /* haz algo con las cabeceras... */

  // siempre liberar los recursos
  curl_easy_cleanup(curl);
}
    
answered by 20.02.2016 / 08:56
source