Im new to network programming and now have a problem with sending some xml data to a server.
I have the following code:
require "net/http"
require "net/https"
require "uri"
xml = <<XML
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?><data appname="dhl_entwicklerportal" language-code="de" password="Dhl_123!" request="get-status- for-public-user"><data piece-code="034234"></data></data>
XML
uri = URI('https://cig.dhl.de/services/sandbox/rest/sendungsverfolgung')
nhttp = Net::HTTP.new(uri.host, uri.port)
nhttp.use_ssl=true
nhttp.verify_mode=OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(uri)
request.basic_auth 'hidden', 'hidden'
response = nhttp.start {|http|
http.request(request, xml: xml)
}
puts response.body
Although i get some response, it is not the right one. For some reason it isn`t sending the body(my xml) properly. If i type the URL manually:
https://cig.dhl.de/services/sandbox/rest/sendungsverfolgung?xml=<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?><data appname="dhl_entwicklerportal" language-code="de" password="Dhl_123!" request="get-status- for-public-user"><data piece-code="034234"></data></data>
it works.
---------------------------EDIT-------------------------------
I edited my code above following the solution from Alex Wayne. Now I get this error:
d:/Ruby200/lib/ruby/2.0.0/net/http/generic_request.rb:179:in `send_request_with_body': undefined method `bytesize' for #<Hash:0x29bcff8> (NoMethodError)