开发者

How to specify "http request header" in OpenURI

开发者 https://www.devze.com 2023-04-05 20:04 出处:网络
I am trying to call a URL using Ruby\'s OpenURI gem开发者_如何学Python, however it needs me to pass certain values inside its HTTP request header.

I am trying to call a URL using Ruby's OpenURI gem开发者_如何学Python, 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" => "foo@bar.invalid",
   "Referer" => "http://www.ruby-lang.org/") {|f|
   # ...
 }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号