Dopo aver guardato un sacco, ho trovato alcune soluzioni che sembrano lavorare, ma non per me ...Come eseguire l'autenticazione di base su HTTP in Ruby?
Per esempio, io ho questo 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
}
quando l'eseguo, dà mi ha una pagina che le richieste per l'autenticazione, ma se scrivo il seguente URL nel browser, ricevo nel sito web senza problemi:
https://my_user:[email protected]/gb/PastSetupsXLS.asp?SR=31,6
ho anche provato con open-uri:
module OpenSSL
module SSL
remove_const :VERIFY_PEER
end
end
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
def 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
end
download('https://www.xxxxxxx.net/gb/PastSetupsXLS.asp?SR=31,6', "target_file.html")
Ma il risultato è lo stesso, il sito richiede l'autenticazione dell'utente. Qualche consiglio su cosa sto sbagliando? Devo codificare la password in Base 64?
Hai provato ad aggiungere il nome utente e la password nell'URL, nello stesso modo in cui lo inseriresti nel browser? –
Sì, certo, ma in questo modo non è supportato per quelle librerie. –