cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: getting cookies from an HTTP request?

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Thu, 28 Jun 2001 23:54:07 +0200 (MET DST)

On Thu, 28 Jun 2001, Dan Wood wrote:

> I'm trying to use libcurl to get a web page, get the cookie that it gives
> me to establish a session, and then use that cookie to get subsequent web
> pages. I have found documentation for *setting* a cookie (using
> CURLOPT_COOKIE in curl_easy_setopt) but I'm trying to figure out:
>
> * How do you grab the Set-Cookie: header from the result of the HTTP
> request? Do I need to parse though the headers myself, or is there some
> function for retrieving it for me?

If you want specific cookie information, you need to parse the headers. I'm
all ears for suggestions on what an interface could be added to aid
applications and authors such as you to extract this kind of info in a
better/easier way.

> * The Set-Cookie header looks like this: Set-Cookie:
> ASPSESSIONIDQGGQGVQO=PCIIPDMDAEJJNDDOHLICDENI; path=/ ... so when I send
> the cookie string with CURLOPT_COOKIE, in the form of [NAME]=[CONTENTS],
> is the NAME just the site URL? Do I include or remove the "path=/" or
> include that in the CONTENTS?

I figure this alone is reason enough to allow an interface...

The Set-Cookie line always only set one single cookie per line. The "path=/"
etc, are only properties that go with that particular cookie. 'path' means
that the server asks you to always pass the cookie back to it when that
particular path on the server is accessed. There are also keywords such as
'domain', 'expires', 'secure' etc, but you should study the standards if you
really want their full meanings.

> As you can see, I'm not intimate with how cookies work. Anybody have any
> sample code that uses this?

You can however store the full set of Set-Cookie headers in a file, and then
later use CURLOPT_COOKIEFILE to have libcurl itself read the cookies from a
file and use the suitable cookies in the request(s). Then you won't need to
understand nor parse them.

I hope this cleared the mist a little.

-- 
     Daniel Stenberg -- curl dude -- http://curl.haxx.se/
_______________________________________________
Curl-library mailing list
http://curl.haxx.se/libcurl/
Received on 2001-06-28