ruby - request_head with basic_auth -


i want know response code without getting whole page content, use #request_head. "401", need pass login/password:

require "net/http"  uri = uri.parse "http://example.com/some_path"  connection = net::http.new(uri.host, 80)  connection.basic_auth "qwe", "rty"  p connection.request_head uri.path 

but get

temp.rb:9:in <main>': undefined methodbasic_auth' #<net::http staging.new.inmyroom.ru:80

since #basic_auth belongs class:

connection = net::http::get.new uri.host 

that doesn't have #request_head:

temp.rb:10:in <main>': undefined methodrequest_head' #<net::http::get get> (nomethoderror)

you can use head http verb.

from rfc2616:

this method (head) can used obtaining metainformation entity implied request > without transferring entity-body itself. method used testing hypertext links validity, accessibility, , recent modification.

something that:

require "net/http"  uri = uri('your_url')  req = net::http::head.new(uri) req.basic_auth('username', 'password')  res = net::http.start(uri.hostname, uri.port) |http|   http.request(req) end 

res contains #<net::httpok 200 ok readbody=true> object.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -