# Uninitialized constant Net::Http

**URL:** <https://rubytalk.org/t/uninitialized-constant-net-http/73856>\
**Category:** ruby-talk\
**Created:** [16 October 2016 17:20 UTC](https://rubytalk.org/t/uninitialized-constant-net-http/73856 "2016-10-16T17:20:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sascha\_K\_Manns](https://avatars.discourse-cdn.com/v4/letter/s/cab0a1/32.png) [@Sascha\_K\_Manns](https://rubytalk.org/u/Sascha_K_Manns)\
**Post date:** [16 October 2016 17:20 UTC](https://rubytalk.org/t/uninitialized-constant-net-http/73856/1 "2016-10-16T17:20:28Z")

</div>

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)

&nbsp;&nbsp;if res.code == "200"  
&nbsp;&nbsp;&nbsp;&nbsp;puts "Gefunden: #{i}"  
&nbsp;&nbsp;elsif res.code == "404"  
&nbsp;&nbsp;&nbsp;&nbsp;puts "Nicht gefunden: #{i}"  
&nbsp;&nbsp;else  
&nbsp;&nbsp;&nbsp;&nbsp;puts "Noch nicht implementierter Fehler: #{i}"  
&nbsp;&nbsp;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](mailto:Sascha.Manns@directbox.com)  
> Jabber: [saigkill@jabber.org](mailto:saigkill@jabber.org)  
> Web: [http://saigkill.github.io](http://saigkill.github.io)  
> Linkedin/Twitter: saigkill  
> Facebook: sascha.manns / Xing: Sascha\_Manns2  
> GPG: FA19BD01 @ hkp://keyserver.ubuntu.com  
> S/MIME: 084E5A5C @ [cacert.org](http://cacert.org)

---

<div class="post-metadata">

**Author:** ![Stefano\_Crocco](https://avatars.discourse-cdn.com/v4/letter/s/5f9b8f/32.png) [@Stefano\_Crocco](https://rubytalk.org/u/Stefano_Crocco)\
**Post date:** [16 October 2016 17:24 UTC](https://rubytalk.org/t/uninitialized-constant-net-http/73856/2 "2016-10-16T17:24:11Z")

</div>

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)
> > 
> > &nbsp;&nbsp;if res.code == "200"  
> > &nbsp;&nbsp;&nbsp;&nbsp;puts "Gefunden: #{i}"  
> > &nbsp;&nbsp;elsif res.code == "404"  
> > &nbsp;&nbsp;&nbsp;&nbsp;puts "Nicht gefunden: #{i}"  
> > &nbsp;&nbsp;else  
> > &nbsp;&nbsp;&nbsp;&nbsp;puts "Noch nicht implementierter Fehler: #{i}"  
> > &nbsp;&nbsp;end
> > 
> > end
> > 
> > A execution gets me "uninitialized constant Net::Http". Maybe i missed a  
> > thing?
> > 
> > Greetings  
> > Sascha

---

<div class="post-metadata">

**Author:** ![Alireza\_Bashiri](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@Alireza\_Bashiri](https://rubytalk.org/u/Alireza_Bashiri)\
**Post date:** [16 October 2016 17:34 UTC](https://rubytalk.org/t/uninitialized-constant-net-http/73856/3 "2016-10-16T17:34:49Z")

</div>

​Hey, you should use "Net::HTTP" instead of "Net::Http".

---

<div class="post-metadata">

**Author:** ![Sascha\_K\_Manns](https://avatars.discourse-cdn.com/v4/letter/s/cab0a1/32.png) [@Sascha\_K\_Manns](https://rubytalk.org/u/Sascha_K_Manns)\
**Post date:** [16 October 2016 17:47 UTC](https://rubytalk.org/t/uninitialized-constant-net-http/73856/4 "2016-10-16T17:47:08Z")

</div>

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](http://saigkill.github.io)  
> Linkedin/Twitter: saigkill  
> Facebook: sascha.manns / Xing: Sascha\_Manns2  
> GPG: FA19BD01 @ hkp://keyserver.ubuntu.com  
> S/MIME: 084E5A5C @ cacert.org
