1
votes

How can I grab an HTML response when there are no response headers?

I've got this:

require 'hpricot'
require 'open-uri'

doc = Hpricot(open('http://192.168.100.1/phy.htm'))

The server in this case is a cable modem that is not returning HTTP Response headers.

The above code is failing with:

C:/Ruby/lib/ruby/1.8/net/http.rb:2022:in `read_status_line': wrong status line: "" (Net::HTTPBadResponse)

from C:/Ruby/lib/ruby/1.8/net/http.rb:2009:in `read_new'

from C:/Ruby/lib/ruby/1.8/net/http.rb:1050:in `request'

from C:/Ruby/lib/ruby/1.8/open-uri.rb:248:in `open_http'

2
You should first determine what it IS sending with curl or your favorite packet sniffer. It would probably be easier and more helpful to simply test your cable from the service drop forward.Azeem.Butt
What I'm trying to do is irrelevant to the question -- I've edited the question to remove the reason I'm trying to do this.John Naegle

2 Answers

4
votes

So if your server is not HTTP compliant, maybe you should drop HTTP idea altogether and work with Socket directly...

Then you can use hpricot with a string returned.

0
votes

I see a similar problem and am reluctantly coming to the same conclusion. I'm talking to a device that returns raw XML without bothering to wrap it in an HTML response.

There is a work around:

resultxml = %x{wget -qO- "http://192.168.100.1/state.xml"}