to chech the url is valid when using Net::HTTP.get_response(

M

Mano Ah

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
 

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

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,278
Latest member
BuzzDefenderpro

Latest Threads

Top