cURL / Mailing Lists / curl-library / Single Mail


Re: API for getting header

From: Joerg Mueller-Tolk <>
Date: Thu, 18 Sep 2003 09:15:34 +0200
Jerry G. Chiuan wrote:
> On Wed, 17 Sep 2003 wrote:
> > I only know we can use curl_slist_append( ) to customize my own header for
> > requests but another way around, does libcurl have any API to let us get
> > header fields from response returned by http server?
> Yes it has. CURLOPT_HEADERFUNCTION is the option you want.
> This is described in the tutorial.
Hi Daniel,
do we need to do something like this after CURLOPT_HEADERFUNCTION?
curl_easy_setopt(m_curlHandle, CURLOPT_FILE, (void *)myAppData);        // for retrive header
I don't know whether it is the right one to use for CURLOPT_HEADERFUNCTION ( sorry, I don't see it is mentioned in document )
and, the ptr ( 1st parameter ) passed into CURLOPT_HEADERFUNCTION is (char *)? 
The following is an excerpt from the curl_easy_setopt() documentation
           Function  pointer that should match the following pro-
           totype:  size_t  function(  void  *ptr,  size_t  size,
           size_t  nmemb,  void  *stream);.  This  function  gets
           called by libcurl as soon as there is received  header
           data  that  needs  to be written down. The headers are
           guaranteed to be written one-by-one and only  complete
           lines  are  written.  Parsing  headers  should be easy
           enough using this. The size of the data pointed to  by
           ptr  is size multiplied with nmemb.  The pointer named
           stream will be the one you passed to libcurl with  the
           CURLOPT_WRITEHEADER  option.   Return  the  number  of
           bytes actually written or return -1 to signal error to
           the  library  (it  will cause it to abort the transfer
           with a CURLE_WRITE_ERROR return code).

What you have to do is writing a function like:

size_t myPrivateHeaderFunction(void *myParameter, size_t size, size_t  nmemb, void *stream)
     *myData = (myStruct*)myParameter;


And use it like:
myStruct Data;
curl_easy_setopt(m_curlHandle, CURLOPT_WRITEHEADER, (void*)&Data);
curl_easy_setopt(m_curlHandle, CURLOPT_HEADERFUNCTION, myPrivateHeaderFunction);

Hope it helps

Joerg M-T
------------------------------------------------------- This email is sponsored by:ThinkGeek Welcome to geek heaven. Received on 2003-09-18