So for my own geeky pleasure, I decided to try writing cgi scripts with Ruby, Python, PHP, and Perl.  All had readily accessible documentation on how to POST to a https URL but ruby. My first thought was to look at the Net:HTTP documentation found HERE.

The one example I wanted was not listed. I did some searching around and pieced together the following code. I hope this is as big a help to you as it was to me. Looking at it, It seems pretty intuitive….but if your like me, sometimes you need it spelled out 😀

As a side note, setting path to path = ‘/../’ is my work-around for a script that is mapped to rather than ‘/some_POST_handling_script.rb’

#Juan Vazquez ->
require 'net/http'
require 'net/https'
http ='', 443)
http.use_ssl = true
#path(a.k.a) ->'
path = '/some_POST_handling_script.rb'
data = 'badguy=Gargamel'

headers = {'Content-Type'=> 'application/x-www-form-urlencoded'}

resp, data =, data, headers)

puts 'Code = ' + resp.code
puts 'Message = ' + resp.message
resp.each {|key, val| puts key + ' = ' + val}
puts data

2 thoughts on “Ruby HTTPS POST’ing

Leave a Reply

Your email address will not be published. Required fields are marked *