Name or service not known

J

Joe Johnson

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
 
G

gabriele renzi

il Tue, 28 Oct 2003 13:08:15 -0700, Joe Johnson
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
 

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

No members online now.

Forum statistics

Threads
474,139
Messages
2,570,805
Members
47,351
Latest member
LolaD32479

Latest Threads

Top