# Question for http experts

**URL:** <https://rubytalk.org/t/question-for-http-experts/8619>\
**Category:** ruby-talk\
**Created:** [25 October 2003 20:00 UTC](https://rubytalk.org/t/question-for-http-experts/8619 "2003-10-25T20:00:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew\_Walrond1](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@Andrew\_Walrond1](https://rubytalk.org/u/Andrew_Walrond1)\
**Post date:** [25 October 2003 20:00 UTC](https://rubytalk.org/t/question-for-http-experts/8619/1 "2003-10-25T20:00:10Z")

</div>

I have to type  
[http://username:password@www.some.url/downloads/file](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

---

<div class="post-metadata">

**Author:** ![Bill\_Kelly](https://avatars.discourse-cdn.com/v4/letter/b/cc9497/32.png) [@Bill\_Kelly](https://rubytalk.org/u/Bill_Kelly)\
**Post date:** [25 October 2003 20:51 UTC](https://rubytalk.org/t/question-for-http-experts/8619/2 "2003-10-25T20:51:31Z")

</div>

Hi,

> I have to type  
> [http://username:password@www.some.url/downloads/file](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

> **···**
>
> From: “Andrew Walrond” [andrew@walrond.org](mailto:andrew@walrond.org)

---

<div class="post-metadata">

**Author:** ![Andrew\_Walrond1](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@Andrew\_Walrond1](https://rubytalk.org/u/Andrew_Walrond1)\
**Post date:** [25 October 2003 21:10 UTC](https://rubytalk.org/t/question-for-http-experts/8619/3 "2003-10-25T21:10:46Z")

</div>

Hi Bill

> **···**
>
> On Saturday 25 Oct 2003 9:51 pm, Bill Kelly wrote:
> 
> > Hope this helps,
> 
> It certainly did; works perfectly!
> 
> Many thanks
> 
> Andrew
