Post xml over https connection

Has anyone posted xml data over a https connection? We have a vendor
product that has an API that allows for programmatic operation. Data is
exchanged in xml format. The exchange occurs over https. Any tips or
ideas would be appreciated. I can open https connection, but I’m not
sure how to post raw XML over the connections.

Thanks

On 14.08.2007 22:05, brad wrote:

Has anyone posted xml data over a https connection? We have a vendor
product that has an API that allows for programmatic operation. Data is
exchanged in xml format. The exchange occurs over https. Any tips or
ideas would be appreciated. I can open https connection, but I’m not
sure how to post raw XML over the connections.

Just like with HTTP: set the content type to “text/xml” and send (post)
the data.

Kind regards

robert

can open https connection, but I’m not sure how to post raw
XML over the connections.

Thanks

Just in case it applies here - a lot of such APIs are implemented as
XML-RPC.
If yours is, try
http://www.ruby-doc.org/stdlib/libdoc/xmlrpc/rdoc/index.html

HTH,

Felix

Robert K. wrote:

Just like with HTTP: set the content type to “text/xml” and send (post)
the data.

Kind regards

robert

Perhaps I’m doing something wrong. Here’s what I’m trying:

nex = Net::HTTP.new(“https://127.0.0.1”, port)
nex.use_ssl = true
path = ‘/path/to/xml_interface/’
headers = {‘Content-Type’ => ‘text/xml’}
resp, data = nex.post(path, data, headers)

I get this error:

/usr/lib/ruby/1.8/net/http.rb:560:in initialize': getaddrinfo: Name or service not known (SocketError) from /usr/lib/ruby/1.8/net/http.rb:560:in open’
from /usr/lib/ruby/1.8/net/http.rb:560:in connect' from /usr/lib/ruby/1.8/timeout.rb:48:in timeout’
from /usr/lib/ruby/1.8/timeout.rb:76:in timeout' from /usr/lib/ruby/1.8/net/http.rb:560:in connect’
from /usr/lib/ruby/1.8/net/http.rb:553:in do_start' from /usr/lib/ruby/1.8/net/http.rb:542:in start’
from /usr/lib/ruby/1.8/net/http.rb:1032:in request' from /usr/lib/ruby/1.8/net/http.rb:842:in post’

The code works up until the actual post attempt. Any ideas?

Keith F. wrote:

data = “foo”
headers = {‘Content-Type’ => ‘text/xml’}

warning, uri.path will drop queries, use uri.path + uri.query if you need to

resp, body = nex.post(uri.path, data, headers)

HTH,
Keith

That was silly of me. Thank you for the example and the doc pointer. I
have it working now.

On 8/15/07, brad [email protected] wrote:

Robert K. wrote:
Perhaps I’m doing something wrong. Here’s what I’m trying:

nex = Net::HTTP.new(“https://127.0.0.1”, port)
nex.use_ssl = true
path = ‘/path/to/xml_interface/’
headers = {‘Content-Type’ => ‘text/xml’}
resp, data = nex.post(path, data, headers)

(Not sure that ‘data’ is set correctly above…)

You’ll want to pass HTTP.new an address, not a URL:
http://www.ruby-doc.org/stdlib/libdoc/net/http/rdoc/index.html

Something like:
require ‘net/https’
require ‘uri’
url = “https://127.0.0.1:7891/path/to/xml_interface
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true if (uri.scheme == ‘https’)
data = “foo”
headers = {‘Content-Type’ => ‘text/xml’}

warning, uri.path will drop queries, use uri.path + uri.query if you

need to
resp, body = nex.post(uri.path, data, headers)

HTH,
Keith