[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Question for http experts

Andrew Walrond

10/25/2003 8:00:00 PM

I have to type
http://username:password@www.some.url/downloads/file
into a browser to download a file. How can I do this with the net/http module
in ruby?

I have tried:

require 'net/http'
h = Net::HTTP.new('username:password@www.some.url')
h.get('/downloads/file',nil,'destfile')

Which works fine for files without the username:password@ part, but here gives

SocketError: getaddrinfo: Name or service not known

I am totally html ignorant, so any suggestions greatly apprieciated!

Andrew Walrond


2 Answers

Bill Kelly

10/25/2003 8:52:00 PM

0

Hi,

From: "Andrew Walrond" <andrew@walrond.org>
>
> I have to type
> http://username:password@www.some.url/downloads/file
> into a browser to download a file. How can I do this with the net/http module
> in ruby?

There's - I suspect - a more elegant way to do this, but here's
what I use:


require 'net/http'
require 'base64'

user_pass = "username:password"
auth_header = { 'Authorization' => 'Basic '+encode64(user_pass).chop }

http = Net::HTTP.new('www.some.host')
resp, data = http.get("/some_page.html", auth_header)


Hope this helps,

Bill



Andrew Walrond

10/25/2003 9:11:00 PM

0

Hi Bill

On Saturday 25 Oct 2003 9:51 pm, Bill Kelly wrote:
>
> Hope this helps,
>

It certainly did; works perfectly!

Many thanks

Andrew