# To chech the url is valid when using Net::HTTP.get\_response(

**URL:** <https://www.ruby-forum.com/t/to-chech-the-url-is-valid-when-using-net-http-get-response/145812>\
**Category:** Ruby\
**Created:** [August 14, 2008, 8:26am UTC](https://www.ruby-forum.com/t/to-chech-the-url-is-valid-when-using-net-http-get-response/145812 "2008-08-14T08:26:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![manoah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@manoah](https://www.ruby-forum.com/u/manoah)\
**Post date:** [August 14, 2008, 8:26am UTC](https://www.ruby-forum.com/t/to-chech-the-url-is-valid-when-using-net-http-get-response/145812/1 "2008-08-14T08:26:03Z")

</div>

I am using Net::HTTP.get\_response( URI.parse( url ) ) to get the reponse  
from  
a website. I have to test it with invalid url. How can i handle it if an  
ivalid url is provided and to give and error message.

def method

```
  response = Net::HTTP.get_response( URI.parse( url ) )

  r = 3; while r> 0 and
    ( response.is_a? Net::HTTPFound or
      response.is_a? Net::HTTPSeeOther )

  location = URI.parse( response['location'] )

  cookie = response.get_fields( 'Set-Cookie' )

  cookie.map! { | c | c.split( ';' ).first }

  cookie = cookie.join( '; ' )

```

end
