Quantcast
Channel: Active questions tagged https - Stack Overflow
Viewing all articles
Browse latest Browse all 1534

How to do basic authentication over HTTPs in Ruby?

$
0
0

After looking a lot, I've found some solutions that seem working, but not for me...

For example, I have this script:

require 'net/http'require "net/https"@http=Net::HTTP.new('www.xxxxxxx.net', 443)@http.use_ssl = true@http.verify_mode = OpenSSL::SSL::VERIFY_NONE@http.start() {|http|    req = Net::HTTP::Get.new('/gb/PastSetupsXLS.asp?SR=31,6')    req.basic_auth 'my_user', 'my_password'    response = http.request(req)    print response.body}

When I run it, it gives me a page that requests for authentication, but if I write the following URL in the browser, I get into the website without problems:

https://my_user:my_password@www.xxxxxxx.net/gb/PastSetupsXLS.asp?SR=31,6

I have also tried with open-uri:

module OpenSSL    module SSL        remove_const :VERIFY_PEER    endendOpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONEdef download(full_url, to_here)    writeOut = open(to_here, "wb")     writeOut.write(open(full_url, :http_basic_authentication=>["my_user", "my_password"]).read)     writeOut.close enddownload('https://www.xxxxxxx.net/gb/PastSetupsXLS.asp?SR=31,6', "target_file.html")

But the result is the same, the site is asking for user authentication.Any tips of what am I doing wrong?. Must I encode the password in Base 64?


Viewing all articles
Browse latest Browse all 1534

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>