# Server-to-Server SSL Connection

**URL:** <https://www.ruby-forum.com/t/server-to-server-ssl-connection/107855>\
**Category:** Rails\
**Created:** [June 26, 2007, 10:22pm UTC](https://www.ruby-forum.com/t/server-to-server-ssl-connection/107855 "2007-06-26T22:22:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ChrisN](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ec9cab/32.png) [@ChrisN](https://www.ruby-forum.com/u/ChrisN)\
**Post date:** [June 26, 2007, 10:22pm UTC](https://www.ruby-forum.com/t/server-to-server-ssl-connection/107855/1 "2007-06-26T22:22:15Z")

</div>

Hi everyone,

I need to make a server-to-server connection in my rails app to confirm  
online credit card payments on the fly. When the confirm payment action  
is run it calls a method in the ‘Order’ model object, the model attempts  
to make an SSL connection to the payment gateway to confirm the payment  
using the following code:

# url: payment gateway domain name

# path: relative path to confirmation script

# params: string of HTTP params

http = Net::HTTP.new(url, 443)  
http.use\_ssl = true  
resp, data = http.post(path, params)

The http.post() call returns the following error:

No such file or directory

/usr/lib/ruby/1.8/net/http.rb:586:in `connect' /usr/lib/ruby/1.8/net/http.rb:586:in`connect’  
/usr/lib/ruby/1.8/net/http.rb:553:in `do_start' /usr/lib/ruby/1.8/net/http.rb:542:in`start’  
/usr/lib/ruby/1.8/net/http.rb:1032:in `request' /usr/lib/ruby/1.8/net/http.rb:842:in`post’  
#{RAILS\_ROOT}/app/models/order.rb:59:in `confirm_payment' #{RAILS_ROOT}/app/controllers/store_controller.rb:221:in`payment\_approved’

Now, the code snippet above works 100% everywhere except when I try to  
use it in a Rails app. The only way I can make this work in Rails is to  
use nonsecure https rather than SSL, however the payment gateway  
requires an SSL POST request to do the confirmation. The error is  
obviously SSL specific, I have traced back through the Ruby code as far  
as I can, any further entails tracing back through openssl.so. Has  
anyone been ably to make this work?

Thanks,  
Chris

---

<div class="post-metadata">

**Author:** ![ChrisN](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ec9cab/32.png) [@ChrisN](https://www.ruby-forum.com/u/ChrisN)\
**Post date:** [July 3, 2007, 10:17pm UTC](https://www.ruby-forum.com/t/server-to-server-ssl-connection/107855/2 "2007-07-03T22:17:52Z")

</div>

Nobody has any insight on this one? Has no one needed to make a secure  
server-to-server connection in a Rails app before?

---

<div class="post-metadata">

**Author:** ![ChrisN](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ec9cab/32.png) [@ChrisN](https://www.ruby-forum.com/u/ChrisN)\
**Post date:** [July 3, 2007, 10:57pm UTC](https://www.ruby-forum.com/t/server-to-server-ssl-connection/107855/3 "2007-07-03T22:57:38Z")

</div>

On Jul 3, 2007, at 2:17 PM, ChrisN wrote:

> Nobody has any insight on this one? Has no one needed to make a  
> secure  
> server-to-server connection in a Rails app before?

This works for me, but I don’t need to do a post.

require ‘socket’  
require ‘openssl’

socket = TCPSocket.new(“[www.url.net](http://www.url.net)”)  
ssl\_context = OpenSSL::SSL::SSLContext.new()  
unless ssl\_context.verify\_mode  
warn “warning: peer certificate won’t be verified this session.”  
ssl\_context.verify\_mode = OpenSSL::SSL::VERIFY\_NONE  
end  
sslsocket = OpenSSL::SSL::SSLSocket.new(socket, ssl\_context)  
sslsocket.sync\_close = true  
sslsocket.connect  
sslsocket.puts(“some text”)

while line = sslsocket.gets  
p line  
end
