嗨,這是我第一個Ruby程序。 我正在嘗試編寫一個簡單的ruby應用程序來向URL發出請求並查看它是否可用。如果是,它將打印確定,否則它將打印錯誤。紅寶石製作網頁請求
這是我到目前爲止,你可以請協助,我需要導入任何庫嗎?
class WebRequest
def initialize(name)
@name = name.capitalize
end
def makeRequest
puts "Hello #{@name}!"
@uri = URI.parse("https://example.com/some/path")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE # read into this
@data = http.get(uri.request_uri)
end
end
req = WebRequest.new("Archie")
req.makeRequest
感謝這幫助了很多! –