On Wednesday 07 June 2006 19:27, Doug Bromley wrote:
> Hi All
>
> I've read the Pickaxe and the Ruby Docs but for the life of me I can't
> figure out an easy way of setting the headers of my HTTP
> request/connection.  I see a class called HTTPHeader and I see some methods
> have an "initheader" parameter but I was expecting there to be a simple way
> of 'adding' headers at any point in the script.  Possible switching them
> and replacing with other values.
There's an example for setting headers using open-uri in the ruby docs: 
http://ruby.outertrack.com/file/ruby-1.8.4%2Flib%2Fopen-uri.rb

  open("http://www.ruby-lang.org/en/",
    "User-Agent" => "Ruby/#{RUBY_VERSION}",
    "From" => "foo / bar.invalid",
    "Referer" => "http://www.ruby-lang.org/") {|f|
    ...
  }

If you're using Net:HTTP directly, initheader is a hash of header values. It's 
really not documented too well there. Unless you feel you need to use 
Net:HTTP, I recommend you use open-uri instead, it does a lot more work for 
you. I'm not sure what you mean by the last part of your question, but you 
can certainly store your hash in a variable and modify it during your 
script's execution as necessary.

> Many thanks for your help.
I hope I've gone some way to answering your question.

> Doug
Alex