Skip to content

Instantly share code, notes, and snippets.

@jeffutter
Created June 19, 2012 01:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffutter/eecccaeb8d43df3f7909 to your computer and use it in GitHub Desktop.
Save jeffutter/eecccaeb8d43df3f7909 to your computer and use it in GitHub Desktop.
Ruby https broken
#! /bin/sh
curl -i -H "Content-Type: application/x-www-form-urlencoded" -X POST -d "orderid=ae5dd847d9f31209cbffeeea076ed966&orderdescription=Active+Merchant+Remote+Test+Purchase&ccnumber=4111111111111111&ccexp=0913&cvv=123&company=Widgets+Inc&address1=1234+My+Street&address2=Apt+1&city=Ottawa&state=ON&zip=K1C2N6&country=CA&phone=%28555%29555-5555&firstname=&lastname=&email=&amount=1.00&type=auth&username=demo&password=password" https://secure.mmoagateway.com/api/transact.php
HTTP/1.1 200 OK
Date: Tue, 19 Jun 2012 01:17:46 GMT
Server: Apache
Content-Length: 240
Connection: close
Content-Type: text/html
response=1&responsetext=SUCCESS&authcode=123456&transactionid=1638794846&avsresponse=N&cvvresponse=N&orderid=ae5dd847d9f31209cbffeeea076ed966&type=auth&response_code=100&merchant_defined_field_6=&merchant_defined_field_7=&customer_vault_id=%
require 'uri'
require 'net/http'
require 'net/https'
endpoint = "https://secure.mmoagateway.com/api/transact.php"
RUBY_184_POST_HEADERS = { "Content-Type" => "application/x-www-form-urlencoded" }
body = "orderid=ae5dd847d9f31209cbffeeea076ed966&orderdescription=Active+Merchant+Remote+Test+Purchase&ccnumber=4111111111111111&ccexp=0913&cvv=123&company=Widgets+Inc&address1=1234+My+Street&address2=Apt+1&city=Ottawa&state=ON&zip=K1C2N6&country=CA&phone=%28555%29555-5555&firstname=&lastname=&email=&amount=1.00&type=auth&username=demo&password=password"
headers = {}
endpoint = endpoint.is_a?(URI) ? endpoint : URI.parse(endpoint)
http = Net::HTTP.new(endpoint.host, endpoint.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.set_debug_output(STDOUT)
result = http.post(endpoint.request_uri, body, RUBY_184_POST_HEADERS.merge(headers))
puts(result)
% ruby test.rb
opening connection to secure.mmoagateway.com...
opened
Conn close because of connect error Connection reset by peer - SSL_connect
/usr/lib/ruby/1.9.1/net/http.rb:799:in `connect': Connection reset by peer - SSL_connect (Errno::ECONNRESET)
from /usr/lib/ruby/1.9.1/net/http.rb:799:in `block in connect'
from /usr/lib/ruby/1.9.1/timeout.rb:54:in `timeout'
from /usr/lib/ruby/1.9.1/timeout.rb:99:in `timeout'
from /usr/lib/ruby/1.9.1/net/http.rb:799:in `connect'
from /usr/lib/ruby/1.9.1/net/http.rb:755:in `do_start'
from /usr/lib/ruby/1.9.1/net/http.rb:744:in `start'
from /usr/lib/ruby/1.9.1/net/http.rb:1284:in `request'
from /usr/lib/ruby/1.9.1/net/http.rb:1307:in `send_entity'
from /usr/lib/ruby/1.9.1/net/http.rb:1096:in `post'
from test.rb:17:in `<main>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment