Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'net/http'
- require 'net/http/digest_auth'
- require 'uri'
- def server_info(s_number = 0)
- output = false
- digest_auth = Net::HTTP::DigestAuth.new
- uri = URI.parse('http://localhost:9999/') #@servers[s_number.to_i - 1]
- uri.user = 'admin'
- uri.password = 'national0987'
- h = Net::HTTP.new uri.host, uri.port
- req = Net::HTTP::Get.new uri.request_uri
- Timeout.timeout(5) do
- begin
- res = h.request req
- # res is a 401 response with a WWW-Authenticate header
- auth = digest_auth.auth_header uri, res['www-authenticate'], 'GET'
- # create a new request with the Authorization header
- req = Net::HTTP::Get.new uri.request_uri
- req.add_field 'Authorization', auth
- # re-issue request with Authorization
- res = h.request req
- output = res.body
- output = false
- rescue
- output = false
- end
- end
- end
- server_info()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement