1

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. Commented Dec 15, 2009 at 22:41
  • 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. Commented Dec 15, 2009 at 23:23

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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"}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.