Sunday 15 February 2015

(rails) weird problem with url validation -


I am trying to see if a url exists or not. Here's my code to do this: url and url.match (URI :: regexp (% w (http https)) Check if # header result:

  Validate: Registered_domain_name_ exists private def register_domain_name_exists Case Net :: HTTP.get_response (URI.parse (url)) When Net :: HTTPSuccess, then the correct else errors.add (URL: "url is not present") and false termination # DNS failures errors .add (: url, "url is not present") and wrong end end  

However, this code is failing, it says that there is no legitimate website. In addition to this, knowing that I also try this URL, and also failed. Then, I know that this can not be possible. What is wrong with my code ??

< / Div>

Each example URL given by you is a redirect (is the HTH status code) 301 or 302). Your code is only considering success for HAB status code 2xx only. Add another case:

  when: NetResources: HTTPRedirection true  

Update: Note that the use of HTTP HEAD instead of GET will transmit low data across the network .

  Yuri = URI response (URL) = Net :: HTTP.start (uri.host, uri.port) {| Http | Http.head ('/')}  

No comments:

Post a Comment