Question

I'm calling a java service via its http endpoint (embedded jetty). The service handles async http requests with a timeout of 5s, and reliably works when I call it from the browser with url params, or curl or py script.

When I call it from a ruby script with net/http or rest-client, it times out half the time?! Any idea what could be causing this and what a possible solution might be (with ruby)?

I'm using ruby 1.9.3-p125 and the ruby and python scripts are all <10 lines (I'd normally be making the call from a larger piece of code, but the small version doesn't work either).

net/http

paramStr = "rid=#{rid}&id=#{id}&json=#{json}"
uri = URI.parse(URI.escape(proxy_server_addr+"?"+paramStr))
response = Net::HTTP.get_response(uri)

rest-client

resource = RestClient::Resource.new('http://myserver.com:9001', :timeout => 10)
response = resource["/"].get :params => {:id => id, :rid => rid, :json => json}

curl

curl 'http://myserver:9001/?id=...'

py

import urllib2
print urllib2.urlopen("http://myserver.com:9001?id=...").read()

enter image description here

Was it helpful?

Solution

You're overcomplicating it. The ruby equivalent of urllib2 is open-uri:

require 'open-uri'
puts open("http://myserver.com:9001?id=...").read
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top