Sending a cookie in the request using Net::HTTP

Discussion in 'Ruby' started by Francis Hwang, Dec 4, 2004.

  1. 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/
     
    Francis Hwang, Dec 4, 2004
    #1
    1. Advertising

  2. Francis Hwang

    Jos Backus Guest

    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'
     
    Jos Backus, Dec 4, 2004
    #2
    1. Advertising

  3. 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/
     
    Francis Hwang, Dec 5, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ad
    Replies:
    2
    Views:
    7,673
    Kevin Spencer
    Jan 27, 2006
  2. itay_k
    Replies:
    2
    Views:
    863
    John J. Lee
    Apr 20, 2006
  3. nRk
    Replies:
    1
    Views:
    1,041
    Steven D'Aprano
    Feb 12, 2009
  4. Paul  Wolpe
    Replies:
    0
    Views:
    175
    Paul Wolpe
    Oct 17, 2005
  5. Richard  Lawrence

    HTTP::Cookie won't store sent cookie

    Richard Lawrence, Mar 17, 2005, in forum: Perl Misc
    Replies:
    4
    Views:
    205
    Richard Lawrence
    Mar 21, 2005
Loading...

Share This Page