One of my background tasks requires administration of bookings for conferences or events. I created an online registration form with javascript validation of credit card numbers and other sundry checks, and if the user submits a registration it is stored as a fairly simple text file on a secure server. The problem I had was to access the secure server forms for plugging stuff into a database etc. For a couple of events, this has all be done manually by my administrator – somewhat of a pain, especially if she was away and we were close to the event and I had to process them myself!
My attempts to automate this were stumped by https access (using OpenSSL). Some brief trials in the past with Ruby failed dismally. I even managed to download OpenSSL and build it and install the Ruby extension – all seemed to work fine but I couldn’t for the life of me manage to successfully login and get the contents of a web page from my secure server. Frustrated, I put it on to the back burner at the time.
Just recently I noticed that the latest Ruby One-Click installer now included the OpenSSL module (which saves lots of hassle, especially as I had had to reinstall my laptop losing the previous OpenSSL installation). This prompted me to search again for examples of how to use it, and this time I eventually turned up a sample from the new Programming Ruby 2nd Edition.
This worked straight off the bat for me and allows me to proceed with the rest of the processing. This is likely to include parsing of the text into an Excel spreadsheet or even Access database.
Code
This is it:
require 'net/https'
USER = "xxx"
PW = "yyy"
site = Net::HTTP.new("www.securestuff.com", 443)
site.use_ssl = true
response = site.get2("/cgi-bin/cokerecipe.cgi",
'Authorization' => 'Basic ' + ["#{USER}:#{PW}"].pack('m').strip)
print response.body
Easy when you know how!! Thanks to the Pragmatic Programmers!



