cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: getting cookies to work with libcurl c++

From: Dan Fandrich <dan_at_coneharvesters.com>
Date: Tue, 17 Aug 2010 14:08:31 -0700

On Tue, Aug 17, 2010 at 09:40:26PM +0100, Shaaa wrote:
> I am trying to get cookies for libcurl working in my C++ app. I have messed
> around with the code for 2 days to no avail and am hoping someone can point out
> the problem with my code:
>
> string url = "http://mysite.com/get=1"
> / Now set up all of the curl options
> curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorBuffer);
> curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
> curl_easy_setopt(curl, CURLOPT_HEADER, 1);
> curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
> curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer);
> curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
> curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "cookie.txt");
> curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "cookie.txt");      

Define "working". What *does* happen with your code? If your server sends a
cookie, you should see it in the file cookie.txt after the transfer
completes. Note that when passing in integers to curl_easy_setopt, they have
to be of type long, not int.

> // Attempt to retrieve the remote page
> result = curl_easy_perform(curl);
>
> // Always cleanup
> curl_easy_cleanup(curl);
>
> // Did we succeed?
> if (result == CURLE_OK)
> {
> }

>>> Dan
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-users
FAQ: http://curl.haxx.se/docs/faq.html
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2010-08-17