Hello list,
i have written a small script with defined urls. The script should check a url
and make a reaction based on the response code:
#!/usr/bin/env ruby
# encoding: UTF-8
require "net/http"
url0 = "..."
%w(url0 url1 url2 url3 url4 url5 url6 url7 url8).each do |i|
url = URI.parse(i)
req = Net::Http.new(url.host, url.port)
res = req.request_head(url.path)
if res.code == "200"
puts "Gefunden: #{i}"
elsif res.code == "404"
puts "Nicht gefunden: #{i}"
else
puts "Noch nicht implementierter Fehler: #{i}"
end
end
A execution gets me "uninitialized constant Net::Http". Maybe i missed a
thing?
Greetings
Sascha
···
--
Sincerly yours
Sascha Manns
Maifeldstraße 10
56727 Mayen
Phone: +49-1573-9242730 (mobile)
Phone: +49-2651-4014045 (home)
Email: Sascha.Manns@directbox.com
Jabber: saigkill@jabber.org
Web: http://saigkill.github.io
Linkedin/Twitter: saigkill
Facebook: sascha.manns / Xing: Sascha_Manns2
GPG: FA19BD01 @ hkp://keyserver.ubuntu.com
S/MIME: 084E5A5C @ cacert.org
I may be wrong, but shouldn't it be Net::HTTP?
Stefano
···
On Sunday 16 October 2016 19:20:28 Sascha Manns wrote:
Hello list,
i have written a small script with defined urls. The script should check a
url and make a reaction based on the response code:
#!/usr/bin/env ruby
# encoding: UTF-8
require "net/http"
url0 = "..."
%w(url0 url1 url2 url3 url4 url5 url6 url7 url8).each do |i|
url = URI.parse(i)
req = Net::Http.new(url.host, url.port)
res = req.request_head(url.path)
if res.code == "200"
puts "Gefunden: #{i}"
elsif res.code == "404"
puts "Nicht gefunden: #{i}"
else
puts "Noch nicht implementierter Fehler: #{i}"
end
end
A execution gets me "uninitialized constant Net::Http". Maybe i missed a
thing?
Greetings
Sascha
Hey, you should use "Net::HTTP" instead of "Net::Http".
Thank you all. This fixes the error
···
Am Sonntag, 16. Oktober 2016, 21:04:49 CEST schrieb Alireza Bashiri:
Hey, you should use "Net::HTTP" instead of "Net::Http".
--
Sincerly yours
Sascha Manns
Maifeldstraße 10
56727 Mayen
Phone: +49-1573-9242730 (mobile)
Phone: +49-2651-4014045 (home)
Email: Sascha.Manns@directbox.com
Jabber: saigkill@jabber.org
Web: http://saigkill.github.io
Linkedin/Twitter: saigkill
Facebook: sascha.manns / Xing: Sascha_Manns2
GPG: FA19BD01 @ hkp://keyserver.ubuntu.com
S/MIME: 084E5A5C @ cacert.org