41

I am trying to call a URL using Ruby's OpenURI gem, however it needs me to pass certain values inside its HTTP request header.

Any idea how to do this?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
iwan
  • 7,269
  • 18
  • 48
  • 66

1 Answers1

62

According to the documentation, you can pass a hash of http headers as the second argument to open:

open("http://www.ruby-lang.org/en/",
   "User-Agent" => "Ruby/#{RUBY_VERSION}",
   "From" => "foo@bar.invalid",
   "Referer" => "http://www.ruby-lang.org/") {|f|
   # ...
 }
cam
  • 14,192
  • 1
  • 44
  • 29