我對Ruby很新穎。我試着查看在線文檔,但我還沒有找到任何有效的工具。我想在下面的HTTP請求中包含用戶代理,bot get_response()和get()。有人能指引我朝着正確的方向嗎?HTTP請求中的用戶代理,Ruby
# Preliminary check that Proggit is up
check = Net::HTTP.get_response(URI.parse(proggit_url))
if check.code != "200"
puts "Error contacting Proggit"
return
end
# Attempt to get the json
response = Net::HTTP.get(URI.parse(proggit_url))
if response.nil?
puts "Bad response when fetching Proggit json"
return
end
我認爲這是解決您的問題:http://www.dzone.com/snippets/send-custom-headers-ruby或http://stackoverflow.com/questions/587559/ruby-how-to-make -an-http-get-with-modified-headers – nhahtdh