# Save http response file attachment

**URL:** <https://www.ruby-forum.com/t/save-http-response-file-attachment/149633>\
**Category:** Ruby\
**Created:** [September 27, 2008, 12:59am UTC](https://www.ruby-forum.com/t/save-http-response-file-attachment/149633 "2008-09-27T00:59:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![twerth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/aca169/32.png) [@twerth](https://www.ruby-forum.com/u/twerth)\
**Post date:** [September 27, 2008, 12:59am UTC](https://www.ruby-forum.com/t/save-http-response-file-attachment/149633/1 "2008-09-27T00:59:46Z")

</div>

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](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
