URL check URL validity

Hi everyone,

I have a web app that at some point asks for a URL ... and i need to check that url's validity ... is there a way to do that in RoR... - in C# i would to something along the lines of

HttpWebRequest hReq = (HttpWebRequest)WebRequest.Create(url................);

HttpWebResponse hRes = (HttpWebResponse)hReq.GetResponse(); rCode = hRes.get_StatusCode()...etc

Any input is greatly appreciated.

Thank you,

I would say a lot depends on what criteria you are using to qualify a URL as valid.

require 'uri'

def valid_uri?    begin      myuri = URI.parse(some_string_that_might_be_a_URL)    rescue URI::InvalidURIError      return false    end    # other checks on myuri.host or myuri.scheme to enforce application rules    # return false if myuri.scheme =~ /javascript/i    # etc.    return true end

Something like that?

-Rob

Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com