Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- from requests.auth import HTTPDigestAuth
- import requests
- import json
- headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
- payload = '{"operation": "read-attribute", "name": "server-state", "json.pretty": 1}'
- for x in range(0, 100):
- try:
- response = requests.post('http://localhost:9990/management', data = payload, headers = headers)
- data = json.loads(json.dumps(response.json()))
- print '%i - %s' %(x,data['result'])
- except Exception as inst:
- print(inst.args)
- print(inst)
- ==========================================
- #!/usr/bin/ruby
- require 'uri'
- require 'json'
- require 'net/http'
- require 'net/http/digest_auth'
- digest_auth = Net::HTTP::DigestAuth.new
- uri = URI.parse 'http://localhost:9990/management'
- uri.user = 'test'
- uri.password = 'test'
- headers = {'Content-Type' => "application/json", 'Accept' => "text/plain" }
- params = '{"operation":"read-attribute","name":"server-state","json.pretty":1}'
- h = Net::HTTP.new uri.host, uri.port
- #h.set_debug_output $stderr
- for i in 0..100
- #returns 401
- req = Net::HTTP::Post.new uri.request_uri, headers
- res = h.request req
- #issung the request again with the auth
- digest_auth = Net::HTTP::DigestAuth.new
- auth = digest_auth.auth_header uri, res['www-authenticate'], 'POST'
- req = Net::HTTP::Post.new uri.request_uri, headers
- req.add_field 'Authorization', auth
- req.body = params
- res = h.request req
- parsed_json = JSON.parse(res.body)
- puts "#{i} - " + parsed_json['result']
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement