Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Ruby
HTTP.get problem
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="daz, post: 4475347"] I can't help, unfortunately. I added - h.set_debug_output $stdout # right after Net::HTTP.new and got - opening connection to [URL="http://www.pragmaticprogrammer.com"]www.pragmaticprogrammer.com[/URL]... opened <- "GET /index.html HTTP/1.1\r\nConnection: close\r\nHost: [URL="http://www.pragmaticprogrammer.com\r\n\r\n"]www.pragmaticprogrammer.com\r\n\r\n[/URL]" -> "HTTP/1.1 200 OK\r\n" -> "Date: Sun, 10 Jul 2005 01:36:29 GMT\r\n" [...] and (from your trace, thanks) you will be getting - opening connection to [URL="http://www.pragmaticprogrammer.com"]www.pragmaticprogrammer.com[/URL]... opened [HANG] (It's surprising that it doesn't time out, though.) All I can suggest is that you try with a local server. If you set this going in the background, you should get a response from your browser at [URL]http://127.0.0.1/webrick[/URL] : <servlet.rb> #------------------------------------------------- require 'webrick' include WEBrick # Browser address: [URL]http://127.0.0.1/webrick[/URL] s = HTTPServer.new( :Port => 80 ) class HelloServlet < HTTPServlet::AbstractServlet def do_GET(req, res) # show request in response ! res.body = req.to_s res['Content-Type'] = "text/plain" end end s.mount('/webrick', HelloServlet) trap("INT") { s.shutdown } STDOUT.sync=true puts ' '*30 << '**********************************' puts ' '*30 << '== Ctrl+Break to close server ==' puts ' '*30 << '**********************************' s.start #------------------------------------------------- Then, if everything is OK of course, you could access it from another Ruby session with your modified script: #------------------------------------------------- STDOUT.sync=true require 'net/http' h = Net::HTTP.new('127.0.0.1', 80) h.set_debug_output STDOUT resp, data = h.get('/webrick/xyz', nil) puts '*'*30 if resp.message =~ /\AOK/ print data else puts 'ERROR ...' p resp.message end puts '*'*30 #------------------------------------------------- It does seem like a problem you've got locally rather than Ruby's Net library. Please post back if you find the cause or suspect 'Net' is at fault. Good luck, daz [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Ruby
HTTP.get problem
Top