How to do HEAD instead of GET with libcurl?


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

1 answer


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, "");

  // 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
answered by 20.02.2016 / 08:56