[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

post xml over https connection

byte8bits

8/14/2007 8:05:00 PM

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
4 Answers

Robert Klemme

8/14/2007 9:00:00 PM

0

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

byte8bits

8/15/2007 1:33:00 PM

0

Robert Klemme 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..., 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 Fahlgren

8/15/2007 2:08:00 PM

0

On 8/15/07, brad <byte8bits@gmail.com> wrote:
> Robert Klemme wrote:
> Perhaps I'm doing something wrong. Here's what I'm trying:
>
> nex = Net::HTTP.new("https://127.0..., 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/...

Something like:
require 'net/https'
require 'uri'
url = "https://127.0.0.1:7891/path/to/xml_inter...
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

byte8bits

8/15/2007 2:56:00 PM

0

Keith Fahlgren wrote:

> You'll want to pass HTTP.new an address, not a URL:
> http://www.ruby-doc.org/stdlib/libdoc/net/http/rdoc/...
>
> Something like:
> require 'net/https'
> require 'uri'
> url = "https://127.0.0.1:7891/path/to/xml_inter...
> 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

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