Question for http experts

A

Andrew Walrond

I have to type
http://username:[email protected]/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:p[email protected]')
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
 
B

Bill Kelly

Hi,

From: "Andrew Walrond said:
I have to type
http://username:[email protected]/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
 

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

Members online

Forum statistics

Threads
474,138
Messages
2,570,804
Members
47,349
Latest member
jojonoy597

Latest Threads

Top