# Post xml over https connection

**URL:** <https://rubytalk.org/t/post-xml-over-https-connection/39899>\
**Category:** ruby-talk\
**Created:** [14 August 2007 20:09 UTC](https://rubytalk.org/t/post-xml-over-https-connection/39899 "2007-08-14T20:09:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![brad3](https://avatars.discourse-cdn.com/v4/letter/b/3ab097/32.png) [@brad3](https://rubytalk.org/u/brad3)\
**Post date:** [14 August 2007 20:09 UTC](https://rubytalk.org/t/post-xml-over-https-connection/39899/1 "2007-08-14T20:09:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Robert\_K1](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/robert_k1/32/1830_2.png) [@Robert\_K1](https://rubytalk.org/u/Robert_K1)\
**Post date:** [14 August 2007 21:00 UTC](https://rubytalk.org/t/post-xml-over-https-connection/39899/2 "2007-08-14T21:00:15Z")

</div>

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

Kind regards

&nbsp;&nbsp;robert

> **···**
>
> 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.

---

<div class="post-metadata">

**Author:** ![Felix\_Windt](https://avatars.discourse-cdn.com/v4/letter/f/bc8723/32.png) [@Felix\_Windt](https://rubytalk.org/u/Felix_Windt)\
**Post date:** [15 August 2007 00:11 UTC](https://rubytalk.org/t/post-xml-over-https-connection/39899/3 "2007-08-15T00:11:00Z")

</div>

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](http://www.ruby-doc.org/stdlib/libdoc/xmlrpc/rdoc/index.html)

HTH,

Felix

> **···**
>
> > -----Original Message-----  
> > From: brad [mailto:byte8bits@gmail.com]  
> > Sent: Tuesday, August 14, 2007 1:10 PM  
> > To: ruby-talk ML  
> > Subject: 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

---

<div class="post-metadata">

**Author:** ![brad3](https://avatars.discourse-cdn.com/v4/letter/b/3ab097/32.png) [@brad3](https://rubytalk.org/u/brad3)\
**Post date:** [15 August 2007 13:35 UTC](https://rubytalk.org/t/post-xml-over-https-connection/39899/4 "2007-08-15T13:35:02Z")

</div>

Robert Klemme wrote:

> Just like with HTTP: set the content type to "text/xml" and send (post) the data.
> 
> Kind regards
> 
> &nbsp;&nbsp;&nbsp;&nbsp;robert

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

nex = Net::HTTP.new("[https://127.0.0.1](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)  
&nbsp;&nbsp;from /usr/lib/ruby/1.8/net/http.rb:560:in `open'  
&nbsp;&nbsp;from /usr/lib/ruby/1.8/net/http.rb:560:in `connect'  
&nbsp;&nbsp;from /usr/lib/ruby/1.8/timeout.rb:48:in `timeout'  
&nbsp;&nbsp;from /usr/lib/ruby/1.8/timeout.rb:76:in `timeout'  
&nbsp;&nbsp;from /usr/lib/ruby/1.8/net/http.rb:560:in `connect'  
&nbsp;&nbsp;from /usr/lib/ruby/1.8/net/http.rb:553:in `do\_start'  
&nbsp;&nbsp;from /usr/lib/ruby/1.8/net/http.rb:542:in `start'  
&nbsp;&nbsp;from /usr/lib/ruby/1.8/net/http.rb:1032:in `request'  
&nbsp;&nbsp;from /usr/lib/ruby/1.8/net/http.rb:842:in `post'

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

---

<div class="post-metadata">

**Author:** ![Keith\_Fahlgren](https://avatars.discourse-cdn.com/v4/letter/k/e9c0ed/32.png) [@Keith\_Fahlgren](https://rubytalk.org/u/Keith_Fahlgren)\
**Post date:** [15 August 2007 14:08 UTC](https://rubytalk.org/t/post-xml-over-https-connection/39899/5 "2007-08-15T14:08:18Z")

</div>

(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](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&quot](https://127.0.0.1:7891/path/to/xml_interface&quot);  
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

> **···**
>
> 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.0.1](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)

---

<div class="post-metadata">

**Author:** ![brad3](https://avatars.discourse-cdn.com/v4/letter/b/3ab097/32.png) [@brad3](https://rubytalk.org/u/brad3)\
**Post date:** [15 August 2007 15:00 UTC](https://rubytalk.org/t/post-xml-over-https-connection/39899/6 "2007-08-15T15:00:02Z")

</div>

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/index.html](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&quot](https://127.0.0.1:7891/path/to/xml_interface&quot);  
> 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.
