Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shell :
- curl --digest 'http://monitor:monitor-123@localhost:9990/management' --header "Content-Type: application/json" -d '{"operation":"read-attribute","name":"server-state","json.pretty":1}'
- Ruby :
- #!/usr/bin/ruby
- require 'rubygems'
- require 'net/http'
- require 'json'
- require 'uri'
- require 'net/http/digest_auth'
- digest_auth = Net::HTTP::DigestAuth.new
- url = URI.parse("http://localhost:9990/management")
- url.user = 'monitor'
- url.password = 'monitor-123'
- payload = { "operation" => "read-attribute", "name" => "server-state", "json.pretty" => 1 }
- pj=payload.to_json
- http = Net::HTTP.new(url.host, url.port)
- request = Net::HTTP::Get.new url.path
- response = http.request request
- # response is a 401 response with a WWW-Authenticate header
- auth = digest_auth.auth_header url, response['www-authenticate'], 'POST'
- # create a new request with the Authorization header
- request = Net::HTTP::Post.new(url.path, initheader = {'Content-Type' =>'application/json'})
- request.add_field 'Authorization', auth
- # re-issue request with Authorization
- request.body = pj
- response=http.request(request)
- puts response
Advertisement
Add Comment
Please, Sign In to add comment