curl-library
Re: How to use cookies
Date: Tue, 26 Feb 2002 11:08:57 +0100 (MET)
On Tue, 26 Feb 2002, Ajay Kale wrote:
> I am a new comer to the curl community.
Welcome to our merry corner of the world!
> I want to do the following things using curl:
>
> I want to download a file from URL say "https://aatma/download/test.bin"
> The URL is protected by userid and password. For user id and password
> validation another site say "https://meghadut is used. Whenever I access
> URL "https://aatma/download/test.bin" it first takes me to URL
> "https://meghadut" for authentication and then redirects me to the request
> page.
>
> After Authentication I want to store the cookie and send it with every
> subsequent request.
>
> Can anybody guide me on how to store cookies and use it afterwards and
> follow redirects using curl ?
You say 'curl' here and you talk as if you want to use the command line tool
and not the library, yet you post to the curl-library list. I'll answer a bit
genericly and I trust that you'll ask again, more specificly, if it isn't
good enough!
I've tried to describe various cookie tricks using the command line in the
"The Art Of HTTP Scripting Using Curl" document you can read online here:
http://curl.haxx.se/docs/httpscripting.shtml
... and yesterday, I actually filled in a chapter about using cookies with
libcurl in The Guide, which you can read online here:
http://curl.haxx.se/libcurl/c/the-guide.html
Basicly, there are three different ways this can be done:
o Manual. You study the headers and handicraft your own cookie replies. This
pretty much assumes that the site(s) use the same cookie and contents
every time or at least use pre-determined.
o Store in files. Dump headers to a file (or to a cookiejar). Use the file
as input in a subsequent request.
o Store in memory. Enable the cookie parser and when subsequent requests are
made using the same session, the correct cookies are sent back
automaticly.
-- Daniel Stenberg -- curl groks URLs -- http://curl.haxx.se/Received on 2002-02-26