Answer the question
In order to leave comments, you need to log in
Ruby 'net/https'. Programmatic authorization on the site using the post method -> follow the link -> download the file!?
Good day, Lord!
Please tell me, I need to programmatically authorize on the acquirer's website in order to download a file in
CSV
format
that we ended up on the page /admin.html
If - true - download the file:
https://service.rro.ukrcard.com.ua/serv/rro/getRro...
require 'uri'
require 'net/https'
require "json"
uri = URI("https://service.rro.ukrcard.com.ua/serv/auth/login.data")
https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl = true
response, data = https.post(uri.path, nil)
cookie = response.response['set-cookie']
headers = {
'Cookie' => cookie,
'Referer' => 'myRuby',
'Content-Type' => 'application/x-www-form-urlencoded'
}
data = ('login=' + login + '&password=' + password)
response, data = https.post(uri.path, data, headers)
response.each {|key, val| puts key + ' = ' + val}
puts '-------------------------------------------------------------------------------------------------------------'
puts 'Code = ' + response.body
puts '-----------------------------------------'
puts 'Message = ' + response.message
puts '-----------------------------------------'
puts "Cookie \n" + cookie
puts response.class.name
puts "--------------------------------------------------------------------Auth complete----------------------------"
https.open_timeout = 10
https.read_timeout = 10
uri_new = URI.parse("https://service.rro.ukrcard.com.ua/serv/rro/getRroData.data?format=csv")
p uri_new.scheme # => "https"
p uri_new.host # => "service.rro.ukrcard.com.ua"
p uri_new.port # => 443
p uri_new.request_uri # => "/serv/rro/getRroData.data?format=csv"
p uri_new.path # => "/serv/rro/getRroData.data"
p uri_new.query # => "format=csv"
p uri_new.to_s
Answer the question
In order to leave comments, you need to log in
Well now go to the admin link by attaching the cookie.
By the way , docs.seattlerb.org/mechanize would make it easier for you to work and code.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question