# Post xml over https connection

**URL:** <https://www.ruby-forum.com/t/post-xml-over-https-connection/112065>\
**Category:** Ruby\
**Created:** [August 14, 2007, 10:11pm UTC](https://www.ruby-forum.com/t/post-xml-over-https-connection/112065 "2007-08-14T22:11:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![brad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/59ef9b/32.png) [@brad](https://www.ruby-forum.com/u/brad)\
**Post date:** [August 14, 2007, 10:11pm UTC](https://www.ruby-forum.com/t/post-xml-over-https-connection/112065/1 "2007-08-14T22:11:04Z")

</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:** ![brad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/59ef9b/32.png) [@brad](https://www.ruby-forum.com/u/brad)\
**Post date:** [August 14, 2007, 11:04pm UTC](https://www.ruby-forum.com/t/post-xml-over-https-connection/112065/2 "2007-08-14T23:04:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![brad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/59ef9b/32.png) [@brad](https://www.ruby-forum.com/u/brad)\
**Post date:** [August 15, 2007, 2:12am UTC](https://www.ruby-forum.com/t/post-xml-over-https-connection/112065/3 "2007-08-15T02:12:23Z")

</div>

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

HTH,

Felix

---

<div class="post-metadata">

**Author:** ![brad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/59ef9b/32.png) [@brad](https://www.ruby-forum.com/u/brad)\
**Post date:** [August 15, 2007, 3:36pm UTC](https://www.ruby-forum.com/t/post-xml-over-https-connection/112065/4 "2007-08-15T15:36:33Z")

</div>

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](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?

---

<div class="post-metadata">

**Author:** ![brad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/59ef9b/32.png) [@brad](https://www.ruby-forum.com/u/brad)\
**Post date:** [August 15, 2007, 5:02pm UTC](https://www.ruby-forum.com/t/post-xml-over-https-connection/112065/5 "2007-08-15T17:02:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![brad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/59ef9b/32.png) [@brad](https://www.ruby-forum.com/u/brad)\
**Post date:** [August 15, 2007, 4:09pm UTC](https://www.ruby-forum.com/t/post-xml-over-https-connection/112065/6 "2007-08-15T16:09:39Z")

</div>

On 8/15/07, brad [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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](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](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](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
