The below script works however, I'm receiving a 400 "Bad Request" response because the POST must include the below XML data into the HTTP body. I've been trying different ways to get this done with no success. Could someone point me in the right direction?
XML Property file:
<?xml version="1.0" encoding="UTF-8"?>
<spa:data xmlns:spa="http://www.Sparrow.com/" object="Sparrow.PropertyList.1">
<spa:proplist>
<spa:propval name="username">jer</spa:propval>
</spa:proplist>
</spa:data>
Ruby code:
#!/usr/bin/env ruby
require 'net/http'
require 'net/https'
require 'rest-client'
require 'base64'
uri = URI.parse('http://sparrow:3453/rest/api/enum')
xml_data = %{<?xml version="1.0" encoding="UTF-8"?>
<spa:data xmlns:spa="http://www.Sparrow.com/" object="Sparrow.PropertyList.1">
<spa:proplist>
<spa:propval name="username">jer</spa:propval>
</spa:proplist>
</spa:data>}
res = req.post(uri.path, xml_data, {'Content-Type' => 'text/xml', 'Content-Length' => xml_data.length.to_s, "User-Agent" => "VAS-UCIP/3.1/1.0", "Connection" => "keep-alive" })
puts res.body
req = Net::HTTP::Post.new(uri)
puts "Authenticating..."
req.basic_auth 'user', 'secret'
puts "Authenticated..."
#req.ssl = false
puts "Sending XML data..."
puts "Starting HTTP request..."
res = Net::HTTP.start(uri.hostname, uri.port) do |http|
http.request(req)
end
case res
when Net::HTTPSuccess, Net::HTTPRedirection
# OK
else
res.value
end
#puts res.body