Skip to content

Instantly share code, notes, and snippets.

@webdesserts
Created May 24, 2012 19:50
Show Gist options
  • Save webdesserts/2783822 to your computer and use it in GitHub Desktop.
Save webdesserts/2783822 to your computer and use it in GitHub Desktop.
This is a snippet of code for connecting to an https server via Ruby's Net::HTTP class
uri = URI('https://www.your-site.com/home/')
https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl = true
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
# use OpenSSL::SSL::VERIFY_PEER instead and https.ca_file for a verified cert
https.start do |http|
request = Net::HTTP::Get.new uri.request_uri
request.basic_auth 'username','password'
response = https.head('/home/')
response.each do |key, value|
puts key
puts ' '*3 + value
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment