Forked from srikanthjeeva/https GET request with Basic Auth in Ruby
Created
September 5, 2022 08:20
-
-
Save babyking/3b56f1615eec334eb0b52508394fa452 to your computer and use it in GitHub Desktop.
https GET request with Basic Auth in Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/http' | |
require 'net/https' | |
require 'uri' | |
uri = URI('https://example.com/rest/api/2/1') | |
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 | |
request.basic_auth 'username', 'password' | |
response = http.request request # Net::HTTPResponse object | |
puts response | |
puts response.body | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment