manage NET HTTP errors


A

Andrea Campagna

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
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top