Net::HTTP post with ssl

Reading time: less than 1 minute

This code is so atypically verbose for ruby so I can never remember it. Even still, I use it all the time.

def query url, post
  uri = URI.parse url
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true

  # Don't leave this as verify_none outside of testing/tinkering
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE

  request = Net::HTTP::Post.new(uri.request_uri);
  request.set_form_data post

  http.request(request)
end

Date: 2012-Feb-29
Tags: ruby
Previous: Rails3.1 Bootstrap html helpers
Next: on sleep

This page was originally published as a github gist and was imported in December 2017.
Original Gist here.