save http response file attachment


T

Todd Williams

I'm looking for some samples on saving off an attached file from a
response to an HTTPS Post. Here's what I got so far. I was hoping that
read_body would be able to use the block keep pulling the data but all I
get out of this is the first line of the file.

Any help would be appreciated.

-----

require 'uri'
require 'net/https'

uri = URI.parse("https://somewhere.com")
request = Net::HTTP::post.new(uri.path)
params = Hash.new
params["userId"] = "xxxx"
params["userPass"] = "yyyy"
params["reportDateBegin"] = "08%2F01%2F2008"
params["reportDateEnd"] = "08%2F25%2F2008"
params["reportType"] = "1"
request.set_form_data(params)

begin
http_session = Net::HTTP.new(uri.host, uri.port)
http_session.use_ssl = true
http_session.verify_mode = OpenSSL::SSL::VERIFY_NONE
http_session.request(request) do |response|
puts response.content_type
response.read_body do |segment|
#TODO save off information to file
puts segment
end
end
rescue Exception => e
puts e.to_s
end
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top