From: Bertram Scharpf Date: 2007-04-11T20:59:44+09:00 Subject: Re: How come this doesn't work? Hi, Am Mittwoch, 11. Apr 2007, 20:10:22 +0900 schrieb Hey You: > require 'socket' > host = 'www.neopets.com' > begin > h = TCPSocket.new(host,80) > rescue > puts "error: #($!)" > else > h.print "POST > /login.phtml?username=r3MaDi&password=mangaka02&destination=/petcentral.phtml > HTTP/1.1\r\nContent-Type: text/html; > charset=UTF-8\r\nHost:"+host+"\r\n\r\n" > h.print "GET /objects.phtml?type=inventory HTTP/1.1\r\n\r\n" > a = h.read > puts a > File.open('Log.txt','w') do |f| > f.print a > end > end > gets 1. indenting. 2. `else' section is for cleanup. Working code belongs just before `rescue'. 3. Don't forget h.close or use h.open 3. Each request needs an own connection. This is NOT a Ruby subject. require 'socket' class String ; def crlf ; gsub "\n", "\r\n" ; end ; end begin host = 'www.justanotherhttpserver.com' puts "-"*32 [ "POST ...", "GET ..." ].each { |request| TCPSocket.open host, 80 do |h| h.write request.crlf puts h.read puts "-"*32 end } rescue puts "error: #$!" end Bertram -- Bertram Scharpf Stuttgart, Deutschland/Germany http://www.bertram-scharpf.de