cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: How can I setup the http request header in libcurl? And how to check the http response code?

From: ying lcs <yinglcs_at_gmail.com>
Date: Thu, 12 Jul 2007 18:07:01 -0500

On 7/12/07, ying lcs <yinglcs_at_gmail.com> wrote:
> I have the following code to load a url using libcurl:
>
>
> /* init the curl session */
> curl_handle = curl_easy_init();
>
> /* specify URL to get */
> curl_easy_setopt(curl_handle, CURLOPT_URL,
> "http://127.0.0.1/apache2-default/index.html");
>
> curl_easy_perform(curl_handle);
>
> /* cleanup curl stuff */
> curl_easy_cleanup(curl_handle);

>
> can you please tell me how to specify HTTP request header? And how can
> I check just the response code for the response?
>

I find out I can use

struct curl_slist *headerlist = curl_slist_append(headerlist, buf);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);

to set http header in my request. But how can I set "Cache-Control"
to "only-if-cached" in my http request header?

Moreover, can you please tell me how can I do just check the http response code?

> Thank you.
>
Received on 2007-07-13