ruby code to download a file from url with basic authentication

Viewed 2764

I am new to ruby and I am learning it.

I am looking to download a file from one url(eg: https://myurl.com/123/1.zip), with basic authentication. I tried to execute the following ruby script, from windows command prompt..

require 'net/http'

uri = URI('https://myurl.com/123/1.zip')


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 'john@test.com', 'John123'

  response = http.request request # Net::HTTPResponse object

  puts response

  puts response.body
end

When I executed the script, I see no errors but the file isn't downloaded. Could you please kindly correct my code

2 Answers
Related