# Re:HTTP download

**URL:** <https://www.ruby-forum.com/t/re-http-download/193598>\
**Category:** Rails\
**Created:** [August 20, 2010, 11:02am UTC](https://www.ruby-forum.com/t/re-http-download/193598 "2010-08-20T11:02:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Srinidhi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dc4da7/32.png) [@Srinidhi](https://www.ruby-forum.com/u/Srinidhi)\
**Post date:** [August 20, 2010, 11:02am UTC](https://www.ruby-forum.com/t/re-http-download/193598/1 "2010-08-20T11:02:37Z")

</div>

The application i am working requires me to upload and download a any  
type of file. I am using net:HTTP for upload part. The code looks  
somethijng like this. This works perfectly fine.  
uri = URI.parse($URL)  
http = Net::HTTP.new(uri.host, uri.port)  
resp,$payload= http.post(uri.path, $payload, {‘Content-  
type’=\>‘application/HTTPStream’,‘actionrequest’=\>‘upload’,‘userid’=\>  
$senderid,‘password’=\>$sender\_password,‘receiverid’=\>  
$receiverid,‘aprf’=\>$aprf,‘snrf’=\> $snrf,‘datatype’=\>‘binary’})  
puts “The HTTP response is #{resp.code}  
#{resp.message}”  
$resp\_code=resp.code

As notices above the application service is invoked using header file  
commands. Now i want to download a file via HTTP. The change required  
is just in headers. But i am unable to get it to work so far from  
above code.  
Can anybody help.

---

<div class="post-metadata">

**Author:** ![Srinidhi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dc4da7/32.png) [@Srinidhi](https://www.ruby-forum.com/u/Srinidhi)\
**Post date:** [August 20, 2010, 11:30am UTC](https://www.ruby-forum.com/t/re-http-download/193598/2 "2010-08-20T11:30:43Z")

</div>

On 20 Aug 2010, at 07:04, Srinidhi wrote:

> #{resp.message}"  
> $resp\_code=resp.code
> 
> As notices above the application service is invoked using header file  
> commands. Now i want to download a file via HTTP. The change required  
> is just in headers. But i am unable to get it to work so far from  
> above code.  
> Can anybody help.

Apart from the fact that I don’t understand your question (how is the  
“download” code anyway related to the “upload” code you mention?), you  
are using dollar signs to assign your variables, which in Ruby is a  
global variable and except for very rare cases should NEVER be used.  
You are mixing up PHP idioms and syntax with Ruby. It might work  
perfectly fine but it is perfectly wrong in every way.

[http://en.wikibooks.org/wiki/Ruby\_Programming/Syntax/Variables\_and\_Constants](http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Variables_and_Constants)

Best regards

Peter De Berdt
