Skip to content

Instantly share code, notes, and snippets.

@r6m
Created January 5, 2016 05:13
Show Gist options
  • Save r6m/85e35f849389c8208645 to your computer and use it in GitHub Desktop.
Save r6m/85e35f849389c8208645 to your computer and use it in GitHub Desktop.
https get with param using Net::HTTP
#! /usr/bin/env ruby
require 'net/http'
require 'uri'
require 'cgi'
mode = 'prod'
id = '000000'
new = 'true'
uri_domain = 'https://www.example.com'
uri_path =
'/some/path/to/file.cfm'
params =
{:mode => mode, :id => id, :new => new}
uri_string =
uri_domain +
uri_path +
"?" +
params.map{|k,v| "#{k}=#{CGI::escape(v.to_s)}"}.join('&')
uri = URI(uri_string)
Net::HTTP.start(uri.host,
uri.port,
:use_ssl => uri.scheme == 'https',
:verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
request = Net::HTTP::Get.new uri.request_uri
response = http.request request
puts response.inspect
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment