cURL / Mailing Lists / curl-users / Single Mail

curl-users

interaction of CURLOPT_NOBODY and CURLOPT_HTTPGET

From: Eric Cooper <ecc_at_cmu.edu>
Date: Wed, 20 Jul 2005 17:51:24 -0400

The man page says that setting CURLOPT_NOBODY to 0 has no effect, but
that doesn't seem to be true. If I've used NOBODY to do a HEAD, and
then want to do a GET, I have to both set HTTPGET to 1 and NOBODY
to 0. If I omit either one, curl does another HEAD instead of a GET.

Here's a program that reproduces the problem.

--------

#include <stdlib.h>
#include <curl/curl.h>

char *url;
CURL *handle = NULL;
const int TRUE = 1;
const int FALSE = 0;

int
main(int argc, char **argv)
{
    if (argc != 2) {
        fprintf(stderr, "Usage: %s URL\n", argv[0]);
        exit(1);
    }
    url = argv[1];

    handle = curl_easy_init();
    curl_easy_setopt(handle, CURLOPT_VERBOSE, TRUE);
    curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, TRUE);

    curl_easy_setopt(handle, CURLOPT_URL, url);
    curl_easy_setopt(handle, CURLOPT_NOBODY, TRUE);
    curl_easy_perform(handle);

    curl_easy_setopt(handle, CURLOPT_URL, url);
    /* without either of these, curl will use HEAD again instead of GET */
    curl_easy_setopt(handle, CURLOPT_HTTPGET, TRUE);
    curl_easy_setopt(handle, CURLOPT_NOBODY, FALSE);
    curl_easy_perform(handle);

    return 0;
}
Received on 2005-07-21