Saturday, August 11, 2012

Making a http/https post request under a proxy

Here is my post on how to make a https call. http://srikanthjeeva.blogspot.in/2010/06/making-httphttps-post-request.html

Spent a long time in figuring out how to send a https request under a proxy

Here is how it is,

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

uri  = URI('https://IP/api/V1/USERS')

proxy_class = Net::HTTP::Proxy(PROXY_ADDRESS, PROXY_PORT, USERNAME, PASSWORD)

proxy_class.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https', :verify_mode => OpenSSL::SSL::VERIFY_NONE) { |http|
  request = Net::HTTP::Get.new uri.request_uri
  response = http.request request
  puts response.body
}

Hope this helps.
Thanks!

Saturday, March 24, 2012

Ruby Conference Pune, India - March 24, 25 - 2012