How to specify “http request header” in OpenURI

若如初见. 提交于 2021-02-06 06:58:12

问题


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?


回答1:


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|
   # ...
 }


来源:https://stackoverflow.com/questions/7478841/how-to-specify-http-request-header-in-openuri

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!