# Geturl with net/http package

**URL:** <https://rubytalk.org/t/geturl-with-net-http-package/20233>\
**Category:** ruby-talk\
**Created:** [17 August 2005 19:36 UTC](https://rubytalk.org/t/geturl-with-net-http-package/20233 "2005-08-17T19:36:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rasmus\_Debitsch](https://avatars.discourse-cdn.com/v4/letter/r/90ced4/32.png) [@Rasmus\_Debitsch](https://rubytalk.org/u/Rasmus_Debitsch)\
**Post date:** [17 August 2005 19:36 UTC](https://rubytalk.org/t/geturl-with-net-http-package/20233/1 "2005-08-17T19:36:15Z")

</div>

Hello,

I want to retrieve an image from the world wind server using the Ruby http  
package. But I can't get it work. In tcl/tk it works like this:

package require http  
set url "[http://data.worldwind.arc.nasa.gov/t?T=105&L=0&X=81&Y=48](http://data.worldwind.arc.nasa.gov/t?T=105&L=0&X=81&Y=48)"  
set token [::http:geturl $url]  
upvar #0 $token state

and the jpeg image is in the state(body) variable. Using Ruby I expected  
something like this:

require 'net/http'  
server = '[http://data.worldwind.arc.nasa.gov](http://data.worldwind.arc.nasa.gov)'  
request = '/t?T=105&L=0&X=81&Y=48'  
http = Net::HTTP.new(server)  
http.start  
resp,data = http.get(request, nil)  
http.finish

But http.start returns "SocketError: getaddrinfo: no address associated with  
hostname." always. Is there a command like geturl in the net/http package?

> **···**
>
> --  
> Rasmus

---

<div class="post-metadata">

**Author:** ![Brock\_Weaver](https://avatars.discourse-cdn.com/v4/letter/b/7ab992/32.png) [@Brock\_Weaver](https://rubytalk.org/u/Brock_Weaver)\
**Post date:** [17 August 2005 19:55 UTC](https://rubytalk.org/t/geturl-with-net-http-package/20233/2 "2005-08-17T19:55:18Z")

</div>

You behind a proxy? There is another method in http which takes proxy  
host / port as an argument.

> **···**
>
> On 8/17/05, Rasmus Debitsch \<Debitsch@t-online.de\> wrote:
> 
> > Hello,
> > 
> > I want to retrieve an image from the world wind server using the Ruby http  
> > package. But I can't get it work. In tcl/tk it works like this:
> > 
> > package require http  
> > set url "[http://data.worldwind.arc.nasa.gov/t?T=105&L=0&X=81&Y=48&quot](http://data.worldwind.arc.nasa.gov/t?T=105&L=0&X=81&Y=48&quot);  
> > set token [::http:geturl $url]  
> > upvar #0 $token state
> > 
> > and the jpeg image is in the state(body) variable. Using Ruby I expected  
> > something like this:
> > 
> > require 'net/http'  
> > server = '[http://data.worldwind.arc.nasa.gov](http://data.worldwind.arc.nasa.gov)'  
> > request = '/t?T=105&L=0&X=81&Y=48'  
> > http = Net::HTTP.new(server)  
> > http.start  
> > resp,data = http.get(request, nil)  
> > http.finish
> > 
> > But http.start returns "SocketError: getaddrinfo: no address associated with  
> > hostname." always. Is there a command like geturl in the net/http package?  
> > --  
> > Rasmus
> 
> --  
> Brock Weaver  
> [http://www.circaware.com](http://www.circaware.com)

---

<div class="post-metadata">

**Author:** ![Mohit\_Muthanna](https://avatars.discourse-cdn.com/v4/letter/m/57b2e6/32.png) [@Mohit\_Muthanna](https://rubytalk.org/u/Mohit_Muthanna)\
**Post date:** [17 August 2005 20:54 UTC](https://rubytalk.org/t/geturl-with-net-http-package/20233/3 "2005-08-17T20:54:54Z")

</div>

Remove the 'http://' from the 'server' variable.

> **···**
>
> On 8/17/05, Rasmus Debitsch \<Debitsch@t-online.de\> wrote:
> 
> > Hello,
> > 
> > I want to retrieve an image from the world wind server using the Ruby http  
> > package. But I can't get it work. In tcl/tk it works like this:
> > 
> > package require http  
> > set url "[http://data.worldwind.arc.nasa.gov/t?T=105&L=0&X=81&Y=48&quot](http://data.worldwind.arc.nasa.gov/t?T=105&L=0&X=81&Y=48&quot);  
> > set token [::http:geturl $url]  
> > upvar #0 $token state
> > 
> > and the jpeg image is in the state(body) variable. Using Ruby I expected  
> > something like this:
> > 
> > require 'net/http'  
> > server = '[http://data.worldwind.arc.nasa.gov](http://data.worldwind.arc.nasa.gov)'  
> > request = '/t?T=105&L=0&X=81&Y=48'  
> > http = Net::HTTP.new(server)  
> > http.start  
> > resp,data = http.get(request, nil)  
> > http.finish
> > 
> > But http.start returns "SocketError: getaddrinfo: no address associated with  
> > hostname." always. Is there a command like geturl in the net/http package?  
> > --  
> > Rasmus
> 
> --  
> Mohit Muthanna [mohit (at) muthanna (uhuh) com]  
> "There are 10 types of people. Those who understand binary, and those  
> who don't."

---

<div class="post-metadata">

**Author:** ![Daniel\_Berger2](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/daniel_berger2/32/2243_2.png) [@Daniel\_Berger2](https://rubytalk.org/u/Daniel_Berger2)\
**Post date:** [17 August 2005 21:56 UTC](https://rubytalk.org/t/geturl-with-net-http-package/20233/4 "2005-08-17T21:56:14Z")

</div>

Mohit Muthanna wrote:

> Remove the 'http://' from the 'server' variable.

It would take a minimal amount of code to make it work with or without  
the "http://" prefix. Any chance this could be patched?

I also recommend accessors for @address and @port.

Regards,

Dan

---

<div class="post-metadata">

**Author:** ![Rasmus\_Debitsch](https://avatars.discourse-cdn.com/v4/letter/r/90ced4/32.png) [@Rasmus\_Debitsch](https://rubytalk.org/u/Rasmus_Debitsch)\
**Post date:** [18 August 2005 15:01 UTC](https://rubytalk.org/t/geturl-with-net-http-package/20233/5 "2005-08-18T15:01:15Z")

</div>

Now it works. Sometimes it is so easy.  
Thanks,  
Rasmus

"Mohit Muthanna" \<mohit.muthanna@gmail.com\> schrieb im Newsbeitrag  
news:fdb3980a05081713547af1fd61@mail.gmail.com...  
Remove the 'http://' from the 'server' variable.

> **···**
>
> On 8/17/05, Rasmus Debitsch \<Debitsch@t-online.de\> wrote:
> 
> > Hello,
> > 
> > I want to retrieve an image from the world wind server using the Ruby http  
> > package. But I can't get it work. In tcl/tk it works like this:
> > 
> > package require http  
> > set url "[http://data.worldwind.arc.nasa.gov/t?T=105&L=0&X=81&Y=48&quot](http://data.worldwind.arc.nasa.gov/t?T=105&L=0&X=81&Y=48&quot);  
> > set token [::http:geturl $url]  
> > upvar #0 $token state
> > 
> > and the jpeg image is in the state(body) variable. Using Ruby I expected  
> > something like this:
> > 
> > require 'net/http'  
> > server = '[http://data.worldwind.arc.nasa.gov](http://data.worldwind.arc.nasa.gov)'  
> > request = '/t?T=105&L=0&X=81&Y=48'  
> > http = Net::HTTP.new(server)  
> > http.start  
> > resp,data = http.get(request, nil)  
> > http.finish
> > 
> > But http.start returns "SocketError: getaddrinfo: no address associated  
> > with  
> > hostname." always. Is there a command like geturl in the net/http package?  
> > --  
> > Rasmus
> 
> --  
> Mohit Muthanna [mohit (at) muthanna (uhuh) com]  
> "There are 10 types of people. Those who understand binary, and those  
> who don't."

---

<div class="post-metadata">

**Author:** ![Brock\_Weaver](https://avatars.discourse-cdn.com/v4/letter/b/7ab992/32.png) [@Brock\_Weaver](https://rubytalk.org/u/Brock_Weaver)\
**Post date:** [18 August 2005 02:57 UTC](https://rubytalk.org/t/geturl-with-net-http-package/20233/6 "2005-08-18T02:57:40Z")

</div>

I'd say the server method shouldn't accept url specs  
([http://servername](http://servername) is not a server name, it is a url). There could be  
a url or address method which accepts a url (i.e.  
protocol://server:port/request), but the methods server, port, and  
request should accept just that.

> **···**
>
> On 8/17/05, Daniel Berger \<djberg96@gmail.com\> wrote:
> 
> > Mohit Muthanna wrote:  
> > \> Remove the 'http://' from the 'server' variable.
> > 
> > It would take a minimal amount of code to make it work with or without  
> > the "http://" prefix. Any chance this could be patched?
> > 
> > I also recommend accessors for @address and @port.
> > 
> > Regards,
> > 
> > Dan
> 
> --  
> Brock Weaver  
> [http://www.circaware.com](http://www.circaware.com)

---

<div class="post-metadata">

**Author:** ![mathew](https://avatars.discourse-cdn.com/v4/letter/m/5daacb/32.png) [@mathew](https://rubytalk.org/u/mathew)\
**Post date:** [19 August 2005 16:06 UTC](https://rubytalk.org/t/geturl-with-net-http-package/20233/7 "2005-08-19T16:06:16Z")

</div>

Daniel Berger wrote:

> Mohit Muthanna wrote:
> 
> > Remove the 'http://' from the 'server' variable.
> 
> It would take a minimal amount of code to make it work with or without  
> the "http://" prefix. Any chance this could be patched?
> 
> I also recommend accessors for @address and @port.

You should be using the URI class to parse and assemble URLs; there's no need to duplicate that functionality in net/http. URI provides address and port accessors. Also, if you want an easy wrapper around net/http and uri, there's already open-uri.

(Also, I've contributed some improved documentation for net/http which will hopefully make it to ruby-doc.org soon.)

mathew

> **···**
>
> --  
> \<URL:[http://www.pobox.com/~meta/&gt](http://www.pobox.com/~meta/&gt);  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WE HAVE TACOS
