[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Name or service not known

Joe Johnson

10/28/2003 8:08:00 PM

Here's my little code:

-----------------------------------------------------
#!/usr/bin/ruby -w

require 'socket'

def get_web(url)
puts url
begin
t = TCPSocket.new(url, 80)
rescue
puts "error: #{$!}"
else
t.print "GET / HTTP/1.0\n\n"
answer = t.gets(nil)
t.close
end
puts answer
end

get_web('www.yahoo.com') #1
get_web('www.yahoo.com/r/xn') #2


------------------------------------------------------

Call #1 I get a page back, everything's fine.

Call #2 I get the following erorr:

www.yahoo.com/r/xn
error: getaddrinfo: Name or service not known
nil

I tried different pages that have subdirectories in the url,
they all return me the same error.

So it seems to know whenever my url isn't in the form
of www.site.com, I get the error.

Does anyone know how I can fix the problem? TIA!

JJ



2 Answers

gabriele renzi

10/28/2003 8:47:00 PM

0

il Tue, 28 Oct 2003 13:08:15 -0700, Joe Johnson
<joejohnson1111@hotmail.com> ha scritto::


>error: getaddrinfo: Name or service not known
>nil
>
>I tried different pages that have subdirectories in the url,
>they all return me the same error.
>
>So it seems to know whenever my url isn't in the form
>of www.site.com, I get the error.
>
>Does anyone know how I can fix the problem? TIA!

I think you misunderstood how internet works :)
actually, the hostname is just
www.site.com and the /stuff is the local http index.
To work the way you are thinking about, and forget about the http
internals, use Net::HTTP , there is some doc in the pickaxe



Lyle Johnson

10/28/2003 9:01:00 PM

0

Joe Johnson wrote:

> Does anyone know how I can fix the problem? TIA!

What about using the standard 'net/http' library instead? See:

http://www.rubycentral.com/book/lib_ne...

for an example of how to use the Net::HTTP class to grab the contents of
various web pages.

Hope this helps,

Lyle