Slide 14
Slide 14 text
require 'net/http'
rquire 'oj'
uri = URI('https:!//192.168.100.220:8006/api2/json/access/ticket')
req = Net!::HTTP!::Post.new
req['Content-Type'] = 'application/x-!!www-form-urlencoded'
req.body = URI.encode_!!www_form(username: 'xxx@pve', password: 'xxx')
token = {}
Net!::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
res = http.request(req)
token = Oj.load(res.body)&.fetch('data', {})
end
puts token['ticket'] # !=> XXXX
puts token['CSRFPreventionToken'] # !=> XXX