Setting a short HTTP GET timeout

Hi guys,

I’m doing a web crawl on our internal network. I need to execute an
HTTP GET cmd to a REST service, and would like the call to timeout
after, say, 3 seconds - since not all IP’s will respond to the call, and
those that do will respond almost immediately. I’ve tried several
different ways, after scouring the web, but no joy.

The most promising efforts (that don’t work) are:

Setting the read/open timeout values:

http =, 80)
response = http.request("/query"))

and the Timeout object:

http =, 80)
response = nil
timeout(5) {
response = http.request("/query")
)#end timeout

In both cases, it waits until the http.request line times out - 20 or 30
seconds. BTW, I’ve also tried the rest-client library, etc. Very

Thanks much,

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs