Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Sending a cookie in the request using Net::HTTP

Reply
Thread Tools

Sending a cookie in the request using Net::HTTP

 
 
Francis Hwang
Guest
Posts: n/a
 
      12-04-2004
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/



 
Reply With Quote
 
 
 
 
Jos Backus
Guest
Posts: n/a
 
      12-04-2004
On Sun, Dec 05, 2004 at 02:07:17AM +0900, Francis Hwang wrote:
> 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'


 
Reply With Quote
 
 
 
 
Francis Hwang
Guest
Posts: n/a
 
      12-05-2004
Works like a charm. Thanks!

On Dec 4, 2004, at 5:15 PM, Jos Backus wrote:

> On Sun, Dec 05, 2004 at 02:07:17AM +0900, Francis Hwang wrote:
>> 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'
>
>


Francis Hwang
http://fhwang.net/



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
urllib2.Request:: http Request sending successfully, but Responsecontains in valid data. nRk Python 1 02-12-2009 12:53 AM
How to set a cookie using Cookie Module tryg.olson@gmail.com Python 2 01-08-2009 02:39 PM
http request with cookie sending itay_k Python 2 04-20-2006 07:43 PM
What is different between Request.Cookie and Response.Cookie ad ASP .Net 2 01-27-2006 12:54 PM
Any downsides to cookie assignment inside custom class using HttpContext.Current? ASP.NET 2.0 cookie fix? ASP .Net 2 08-17-2005 06:43 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57