RUBY - SSL, Basic Auth, and POST

Viewed 20871

I'm having quite a hard time with this -- seems like there are a few snippets of code lying around that I can't seem to piece together. I'm simply trying to POST key/value pairs, but getting Connection refused - connect(2) (Errno::ECONNREFUSED). Help!

require 'net/http'
require 'net/https'
require 'uri'

@http = Net::HTTP.new('https://my.url.com/path', 443)
@http.use_ssl = true
@http.start() { |http|
    req = Net::HTTP.post_form(
        URI.parse('https:///my.url.com/path'),
        {'key1' => 'value1', 'key2' => 'value2'}
    )
    req.basic_auth 'username', 'password'
    response = http.request(req)
    puts response.body      
}
2 Answers
Related