Net::HTTP works on localhost, but error Errno::ECONNRESET

Hi All,

Newbie here, on XP with Ruby, I am trying to post a request to
an external service basic HTTP/XML Form Post. I have tried multiple
test, but getting this error,

Errno::ECONNRESET (An existing connection was forcibly closed by the
remote host.):
c:/ruby/lib/ruby/1.8/net/protocol.rb:133:in sysread' c:/ruby/lib/ruby/1.8/net/protocol.rb:133:inrbuf_fill’

The code,
url = URI.parse(‘’) # not working
url = URI.parse(‘http://localhost:8080/default.txt’) # working fine

http =
puts "===== Begin ======"
puts url.path
puts url.port

res = Net::HTTP.start(, url.port) {|http|
puts res.body
@result = res.body
puts "===== End ======"

No proxy. Downloading 1.8.5 to give it a try.

Anyone experience similar issue? Recommendation to use other library to
make HTTP/XML call?

Really appreciated!


Well, good news and bad news. I can’t offer to give you one or the
other first because they are the same news item, and either good or
bad depending on the way you look at it, so here goes:

It works for me. (I’m running Linux (Recent Debian).)

Maybe some Windowsy type of Ruby expert can help you more… surely
Net::HTTP works on XP!

Maybe try cygwin’s ruby port? Anyone running Windows should be running
Cygwin, anyway, in my opinion.


Also, I believe that some web servers only repsond to HTTP requests if
they recognize that the request is coming from a legit browser. I’ve
seen a web server send a reset after being unable to recognze the
request. Try emulating a Firefox or IE request over a regular TCPSocket
and see if you get a response. Even easier at first, telnet to the
server and do a regular GET to see if that gives you a response.

Maybe I’m wrong. Hope this helps.

2007/8/10, Caleb M. [email protected]:

res = Net::HTTP.start(, url.port) {|http|

Really appreciated!

The first thing I would make sure is that there are no network issues
(corporate firewall killing off the connection).

Kind regards


Thank you for all the help.

Resolved the issue by downgrading to 1.8.5. :slight_smile: Here’s my sample code.

@hostname = ‘my.hostname’

http =, 443)
http.use_ssl = true
http.start do |http|
  request ='index.html')
  puts 'set content-type done'
  request.basic_auth '', ''
  response = http.request(request, params["body"])
  puts 'making the request...'
  case response
  when Net::HTTPSuccess, Net::HTTPRedirection
    puts 'success'
    @result = response.body
    puts 'Error'

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