0

Hi all i'm trying to post the following from a controller in rails, however I constantly get the following error:

SSL_connect returned=1 errno=0 state=unknown state: sslv3 alert handshake failur

am I doing something wrong?

uri = URI.parse('https://devcheckout.psigate.com/HTMLPost/HTMLMessenger')

form_data = { 'StoreKey' => 'psigatecapturescard001010',
             'CustomerRefNo' => 'Monday Evening Muay Thai Classes',
             'UserID' => 'jsmith',
             'SubTotal' => '34.00'
            }

response = Net::HTTP.post_form(uri, form_data)
user1213904
  • 1,830
  • 4
  • 23
  • 39

2 Answers2

1

check this, the accepted answer could maybe solve your problem:

Using Net::HTTP.get for an https url

also here are some informations about the error returned:

Receiving "SSL_connect returned=1 errno=0 state=SSLv3 read server hello A: sslv3 alert handshake failure" with openshift nodejs app

The errors seems to occur because your Net::HTTP instance use a SSL version (SSLv3) not supported by your server.

Try setting the ssl_version to 'TLSv1'

uri = URI.parse('https://devcheckout.psigate.com/HTMLPost/HTMLMessenger')

form_data = { 'StoreKey' => 'psigatecapturescard001010','CustomerRefNo' => 'Monday Evening Muay Thai Classes','UserID' => 'jsmith', 'SubTotal' => '34.00'}


http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.ssl_version = :TLSv1
http.verify_mode = OpenSSL::SSL::VERIFY_NONE # read into this
@data = http.post(uri.request_uri, form_data.to_query)

tried it, works perfectly fine

Community
  • 1
  • 1
Florian Eck
  • 495
  • 3
  • 13
  • i'm getting the following error wit hthe uri.query_values: undefined method `query_values=' for #. Does the URI class have this method? – user1213904 Mar 11 '15 at 12:21
  • my mistake, left over code from trrying, remove this line :-) it should be form_data = ... i corrected it above – Florian Eck Mar 11 '15 at 12:22
1

Maybe you could do something like this:

uri = URI('https://devcheckout.psigate.com/HTMLPost/HTMLMessenger')
req = Net::HTTP::Post.new(uri)
req.use_ssl = true if uri.scheme == 'https'
req.set_form_data(
                  'StoreKey' => 'psigatecapturescard001010',
                  'CustomerRefNo' => 'Monday Evening Muay Thai Classes',
                  'UserID' => 'jsmith',
                  'SubTotal' => '34.00'
                  )

res = Net::HTTP.start(uri.hostname, uri.port) do |http|
  http.request(req)
end
usmanali
  • 2,028
  • 2
  • 27
  • 38
  • produces 'NoMethodError: undefined method `use_ssl=' for #', also does not solve the real issue: request uses SSLv3, which is old, instead TLSv1 should be used, as pointed out in my answer below – Florian Eck Mar 11 '15 at 12:15