Sending a cookie in the request using Net::HTTP

F

Francis Hwang

I can't find this answered in the RDoc, so I'll ask here: How do I send
the cookie string in an HTTP request using Net::HTTP? I tried doing
something like:

Net::HTTP.start( 'server.host.here' ) { |http|
response = http.get(
'/local/file.rb',
'Cookie: cookie_name=cookie_val'
)
}

hoping that the "initheader" in HTTP#get is where I should drop the
cookie value, but that just gave me a traceback.

Francis Hwang
http://fhwang.net/
 
J

Jos Backus

I can't find this answered in the RDoc, so I'll ask here: How do I send
the cookie string in an HTTP request using Net::HTTP? I tried doing
something like:

Net::HTTP.start( 'server.host.here' ) { |http|
response = http.get(
'/local/file.rb',

Try passing any extra headers in a hash here, like this:

{"Cookie" => 'cookie_name=cookie_val; another_cookie=brownie'}
'Cookie: cookie_name=cookie_val'
)
}

--
Jos Backus _/ _/_/_/ Sunnyvale, CA
_/ _/ _/
_/ _/_/_/
_/ _/ _/ _/
jos at catnook.com _/_/ _/_/_/ require 'std/disclaimer'
 
F

Francis Hwang

Works like a charm. Thanks!

Try passing any extra headers in a hash here, like this:

{"Cookie" => 'cookie_name=cookie_val; another_cookie=brownie'}


--
Jos Backus _/ _/_/_/ Sunnyvale, CA
_/ _/ _/
_/ _/_/_/
_/ _/ _/ _/
jos at catnook.com _/_/ _/_/_/ require
'std/disclaimer'

Francis Hwang
http://fhwang.net/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top