# Absolutely lost with URI/Net/HTTP (part II)

**URL:** <https://www.ruby-forum.com/t/absolutely-lost-with-uri-net-http-part-ii/108435>\
**Category:** Ruby\
**Created:** [July 3, 2007, 2:47pm UTC](https://www.ruby-forum.com/t/absolutely-lost-with-uri-net-http-part-ii/108435 "2007-07-03T14:47:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [July 3, 2007, 2:47pm UTC](https://www.ruby-forum.com/t/absolutely-lost-with-uri-net-http-part-ii/108435/1 "2007-07-03T14:47:06Z")

</div>

Hi, sorry for the repost, but I can’t seem to reply without registering,  
and I can’t seem to register… so I’m in quite a predicament (if  
there’s a way to reply as a guest, please let me know)

I was told this as a solution to my problem:

> is it possible to download a file with a PHP hidden URL?
> 
> when the link is clicked on in firefox, it will prompt the user to  
> either open or save, for example…
> 
> [http://www.esnips.com/nsdoc/b2a4a221-2590-486f-a314-469a4721e1ed/?id=1183359840917](http://www.esnips.com/nsdoc/b2a4a221-2590-486f-a314-469a4721e1ed/?id=1183359840917)
> 
> how can i download this file using ruby?

require “open-uri”

File.open(“my.mp3”,“wb”) do |file|  
file \<\< open(“http://…”)  
end

however, this only works for files that are located directly at that  
location i.e. [http://random](http://random)…/random.mp3, not for php hosted files like  
the examle I had given. Please help!

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [July 3, 2007, 5:42pm UTC](https://www.ruby-forum.com/t/absolutely-lost-with-uri-net-http-part-ii/108435/2 "2007-07-03T17:42:51Z")

</div>

On Tue, Jul 03, 2007 at 09:47:12PM +0900, Guest wrote:

> Hi, sorry for the repost, but I can’t seem to reply without registering,  
> and I can’t seem to register… so I’m in quite a predicament (if  
> there’s a way to reply as a guest, please let me know)

Can’t you subscribe to the mailing list?

[Mailing Lists](http://www.ruby-lang.org/en/community/mailing-lists/)

> > how can i download this file using ruby?
> 
> require “open-uri”
> 
> File.open(“my.mp3”,“wb”) do |file|  
> file \<\< open(“http://…”)  
> end
> 
> however, this only works for files that are located directly at that  
> location i.e. [http://random](http://random)…/random.mp3, not for php hosted files like  
> the examle I had given. Please help!

It looks like you need to log in to the site before you can download  
that file, correct? If that is the case, I suggest using  
WWW::Mechanize. It lets you fill out forms, and manages cookies and  
redirects for you.

[http://mechanize.rubyforge.org/](http://mechanize.rubyforge.org/)
