# Manage NET HTTP errors

**URL:** <https://www.ruby-forum.com/t/manage-net-http-errors/138125>\
**Category:** Ruby\
**Created:** [May 20, 2008, 1:06pm UTC](https://www.ruby-forum.com/t/manage-net-http-errors/138125 "2008-05-20T13:06:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![qwerty73](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/9d8465/32.png) [@qwerty73](https://www.ruby-forum.com/u/qwerty73)\
**Post date:** [May 20, 2008, 1:06pm UTC](https://www.ruby-forum.com/t/manage-net-http-errors/138125/1 "2008-05-20T13:06:13Z")

</div>

Hi to all,

i’ve done a ruby script that restart a VoIP network device. The code i s  
below:

```
            url = URI.parse('http://192.168.0.111/dologin.htm')
            response=Net::HTTP.start(url.host, url.port) {|http|
      req = Net::HTTP::Post.new(url.path)
req.set_form_data({'P2'=>'password', 'Login' => 'login', 'gnkey' =>

```

‘0b82’}, ‘&’)  
res=http.request(req)  
puts res  
cookie=res.get\_fields(‘Set-Cookie’)  
cookie=cookie.to\_s.match(/SessionId=((.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.))/).to\_s  
req=Net::HTTP::Get.new(’/rs.htm’)  
req.add\_field(‘Cookie’,cookie)  
http.request(req)  
}  
case response  
when Net::HTTPSuccess then status=1  
when Net::HTTPClientError then status=2  
when Net::HTTPServerError then status=2  
when Net::HTTPUnknownResponse then status=2  
end

I’ve problems to manage these errors:  
when the device is not connected i get an (Errno::EHOSTUNREACH) or the  
script seems freezed…  
Any suggetion???  
Thanks in advance

Andrea
