ruby - Net::http check actual page -


ok got yesterday checking , actual host see if available. wrote this.

i pass server www.myhost.com , port 81. works perfect. if want check page. www.myhost.com/anypage.php? not sure think problem lies alternate port.

def server_up(server, port)   http = net::http.start(server, port, {open_timeout: 5, read_timeout: 5})   response = http.head("/")   response.code == "200" rescue timeout::error, socketerror   false end 

as tadman mentioned in comments, modify method accept optional path argument (below). may want rename method, though, since no longer check if server up, rather, if page exists.

def server_up(server, port, path="")   http = net::http.start(server, port, {open_timeout: 5, read_timeout: 5})   response = http.head("/#{path}")   response.code == "200" rescue timeout::error, socketerror   false end 

Comments

Popular posts from this blog

matlab - How to equate a structure array to structure array -

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -