如何将此curl
命令转换为Ruby HTTP请求?
curl -k -v -X POST -H "Content-Type: application/json" --data-binary @/home/venafi/venafi-auth.json https://10.150.85.11/authorize/`
我不太了解Ruby,我试过
require 'net/http'
require 'uri'
require 'openssl'
require 'json'
uri = URI.parse("https://10.150.85.1/authorize/")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new(uri.path, initheader = {'Content-Type' =>'application/json'})
request.set_form_data({'Username' => 'user', 'Password' => 'Passw0rd'})
#request['foo'] = 'bar'
puts request
response = http.request(request)
puts "Response\n #{response.code} \n#{response.message}: \n#{response.body.to_json}"
puts response
puts request
httpg = Net::HTTP.new(uri.host, uri.port)
httpg.use_ssl = true
httpg.verify_mode = OpenSSL::SSL::VERIFY_NONE
reqg = Net::HTTP::Get.new("uri.request_uri")
puts "Response\n #{reqg.body.to_json}"
但我唯一得到的是
净:: HTTP ::发表:0x00000001baab98
响应
202个
接受:
“”
网:: HTTPAccepted:0x00000001bcac68
网:: HTTP ::帖子:0x00000001baab98
响应
空
当我使用curl
时,我得到了一个apikey。