Why doesn't my session work when I run my app via curl

I have my app keep state with a session variable in my DB:

session :session_key => ‘_myapp_session_id’

This works find when I login and run my app via my browser.

But when I login via curl, the session doesn’t seem to work, and once
I call a action that need authentication, the can’t find my session
variable. I checked my DB and a row is added everytime I login via
curl, but the rest of my app can’t seem to read the session variable.

What’s going on? Does the session[] only work via a web browser?

eggie5 wrote:

What’s going on? Does the session[] only work via a web browser?
You will most likely need to tell CURL to use the cookie set on login.
Google curl + cookie and there are a few explanations on what is
required. Alternatively you can try and change you app to not use
cookies for tracking sessions (not sure how hard that is in rails).
Anyway I think you can get curl to save the cookie to a file and then
use that in subsequent requests. But I haven’t done it myself.

Cheers,

Anthony R.

Ahhh, thanks alot. I’ve got it working now.

When I login, I need to save my cookie:

eggie5$ curl -d “asfsaf:asfasdf” -c cookie localhost:3000/
authentication/login

Now, all I need to do for any subsequent API calls is to reference my
cookie! e.g.:

eggie5$ curl -b cookie localhost:3000/content_campaigns/5/attachments
[“5_1.3g2”, “5_10.3g2”, “5_11.3gp”, “5_12.3gp”, “5_13.3g2”,
“5_14.mp4”, “5_2.3g2”, “5_3.3g2”, “5_4.3g2”, “5_5.3g2”, “5_6.3g2”,
“5_6.3gp”, “5_7.3g2”, “5_8.3g2”, “5_9.3g2”]

So to save the cookie when you login use curl -c [cookie-file-path]
this saves the cookie text file to your current directory.
Then to reference your cookie in subsequent calls use curl -b [cookie-
file-path]

On Sep 10, 7:14 pm, Anthony R. [email protected]

My guess is Cookies isn’t supported with curl. Perhap my plugin (link
below) may be of help.

Cheers,

– Long
http://MeandmyCity.com/ - Find your way
http://edgesoft.ca/blog/read/2 - No-Cookie Session Support plugin

----- Original Message -----
From: “eggie5” [email protected]
To: “Ruby on Rails: Talk” [email protected]
Sent: Monday, September 10, 2007 8:59 PM
Subject: [Rails] why doesn’t my session work when I run my app via curl

Yes, thanks for the previous post. I did learn something after all

– Long

----- Original Message -----
From: “eggie5” [email protected]
To: “Ruby on Rails: Talk” [email protected]
Sent: Monday, September 10, 2007 10:49 PM
Subject: [Rails] Re: why doesn’t my session work when I run my app via
curl

– Longhttp://MeandmyCity.com/- Find your wayhttp://edgesoft.ca/blog/read/2- No-Cookie Session
Support plugin

No, I figured out how to do it with curl. It’s not too bad. I just
wonder how valid the use of cookies would be for an API… I’m pretty
sure any environment would support cookies: C#, java, ruby, flex…