How to set cookie and session in Ruby?

Hi all. I need to get the response (200 status) from sever which should
return after download button click. I have got cookie and session
successfully but after setting it returned response with 302 status.
Please clarify how to set it correctly in Ruby and where is a mistake.

connection = Faraday.new(EnvConfig.get :app_url) do |faraday|
faraday.request :url_encoded # form-encode POST params
faraday.response :logger # log requests to STDOUT
faraday.adapter Faraday.default_adapter # make requests with
Net::HTTP
end

#post login request for getting cookies
response = connection.post do |req|
req.url ‘/Account/Login’
req.headers[‘Content-Type’] = ‘application/json’
req.body = ‘{ “UserName”: “", “password”:"” }’
end

#Splitting and separate received data
json = response.headers[‘set-cookie’].split(’ ')
asp_net = json[0][18…41]
cookie = json[3][15…-2]
payer_token = json[6][11…-2]

#post request for downloading cvs file (setting all separated data) but
#return the 302 status response
response2 = connection.post do |request1|
request1.url ‘***/*//***/***’
request1.headers[‘ASP.NET_SessionId’] = asp_net
request1.headers[‘cookie’] = cookie
request1.headers[‘PayerToken’] = payer_token
request1.headers[‘Content-Type’] = ‘application/json’
request1.body = ‘{“request”:"{“type”: “All”, “format”: “CSV”}"}’

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs