Forum: Ruby on Rails RestClient and passing cookies

Ee6fb5cad9d1b269f1dcbb5a76c9d760?d=identicon&s=25 Moutalib Abdel (jarh)
on 2014-08-12 22:36

I had this post on the Ruby channel, but maybe I have more luck here :)

I'm struggling with the last piece of the puzzle here. Basically I want
to reuse a cookie that I capture from a previous
login, the only problem is that the second will not
accept it. I have tried different methods to pass the cookie value to
the, but with no success. Also tried the base64
encoding, also failed here. Can someone please advice?

require 'json'
require 'rest-client'

url_login = ''
url_adduser= ''

payload_login = <<-JSON


payload_adduser= <<-JSON_ADDUSER

initheader_login = {'Content-Type' =>
'application/x-www-form-urlencoded',:accept => :json}
initheader_add_user= {'Content-Type' => 'application/x-add-user'}

#the restexec_login goes well, I can see it login on the webserver (code
restexec_login =,payload_login,initheader_login)

#capture the cookie as a result of the execution of restexec_login
query_cookie = restexec_login.cookies
cookie_hash = query_cookie['SESSION_ID']
cookie = {:SESSION_ID => cookie_hash}

#the second post (below) will fail because of the missing cookie


How can I pass the cookie in the second post method?

Thanks in advance!

Kind Regards,

81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2014-08-14 10:37
(Received via mailing list)
On Tuesday, August 12, 2014 9:36:59 PM UTC+1, User wrote:
You need to set a header of the form

    Cookie: cookie_name=cookie_value; other_cookie_name=cookie_value

if your name/value have special characters in them you'll need to quote

Ee6fb5cad9d1b269f1dcbb5a76c9d760?d=identicon&s=25 Moutalib Abdel (jarh)
on 2014-08-16 17:31
Hello Fred,

Thanks for your reply! But the problem was that the cookie was expired
before I could reuse it.


Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.