简体   繁体   中英

How to Store Cookies in Ruby?

I am programmatcally accessing authenticated content in my CDN on Google App Engine, and it's returning a cookie that I'm supposed to store:

{"set-cookie"=>"ACSID=cookie-hash; expires=Mon, 12-Apr-2010 01:56:06 GMT; path=/"}

What do I do with that? This is my first time dealing with Cookies.

I can put in the header of the next request, but what's the recommended way to store that? I'm testing this with irb in the console and when I exit and try again, the cookie is gone.

How do I save it for a few days/weeks? I'm using pure ruby without Rails or anything.

Thanks so much.

Ruby Mechanize has a cookie jar and cookie class. It's fairly straight forward, and seems independent from the rest of the library. You construct and add cookies, specifying the URL, and later you use the cookies method to check which cookies apply to a given URL. You can serialize the jar with save_as and deserialize with load .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM