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?
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?
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" => "[email protected]",
"Referer" => "http://www.ruby-lang.org/") {|f|
# ...
}
URI.open
to avoid deprecations warnings from ruby related to confusion with kernel#open.
–
Gawky © 2022 - 2024 — McMap. All rights reserved.