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? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Anthony Richardson
2007-Sep-11 02:14 UTC
Re: why doesn''t my session work when I run my app via curl
eggie5 wrote:> 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?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 Richardson --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Richardson <anth...-fLWHnXb90il4ktuDPxIMMA@public.gmane.org> wrote:> eggie5 wrote: > > 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? > > 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 Richardson--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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... On Sep 10, 8:51 pm, "Long" <long...-bJEeYj9oJeDQT0dZR+AlfA@public.gmane.org> wrote:> My guess is Cookies isn''t supported with curl. Perhap my plugin (link below) may be of help. > > Cheers, > > -- Longhttp://MeandmyCity.com/- Find your wayhttp://edgesoft.ca/blog/read/2- No-Cookie Session Support plugin > > ----- Original Message ----- > From: "eggie5" <egg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > To: "Ruby on Rails: Talk" <rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > Sent: Monday, September 10, 2007 8:59 PM > Subject: [Rails] 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?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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" <eggie5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> To: "Ruby on Rails: Talk" <rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> Sent: Monday, September 10, 2007 8:59 PM Subject: [Rails] 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? > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Yes, thanks for the previous post. I did learn something after all <g> -- Long ----- Original Message ----- From: "eggie5" <eggie5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> To: "Ruby on Rails: Talk" <rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> Sent: Monday, September 10, 2007 10:49 PM Subject: [Rails] Re: why doesn''t my session work when I run my app via curl> > 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... > > On Sep 10, 8:51 pm, "Long" <long...-bJEeYj9oJeDQT0dZR+AlfA@public.gmane.org> wrote: > > My guess is Cookies isn''t supported with curl. Perhap my plugin (link below) may be of help. > > > > Cheers, > > > > -- Longhttp://MeandmyCity.com/- Find your wayhttp://edgesoft.ca/blog/read/2- No-Cookie SessionSupport plugin> > > > ----- Original Message ----- > > From: "eggie5" <egg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > To: "Ruby on Rails: Talk" <rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > Sent: Monday, September 10, 2007 8:59 PM > > Subject: [Rails] 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? > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---