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

Hi All,

Newbie here, on XP with Ruby 1.8.6.25, 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:in `rbuf_fill'

The code,
    url = URI.parse('http://www.yahoo.com') # not working
    url = URI.parse('http://localhost:8080/default.txt') # working fine

    http = Net::HTTP.new(url.host)
    puts "===== Begin ======"
    puts url.path
    puts url.host
    puts url.port

    res = Net::HTTP.start(url.host, url.port) {|http|
      http.get('/index.htm')
    }
    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!

Cheers,
Calebmei

···

--
Posted via http://www.ruby-forum.com/.

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.

-rking

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

Kind regards

robert

···

2007/8/10, Caleb Mei <tommy_tam@intuit.com>:

Hi All,

Newbie here, on XP with Ruby 1.8.6.25, 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:in `rbuf_fill'

The code,
    url = URI.parse('http://www.yahoo.com') # not working
    url = URI.parse('http://localhost:8080/default.txt&#39;\) # working fine

    http = Net::HTTP.new(url.host)
    puts "===== Begin ======"
    puts url.path
    puts url.host
    puts url.port

    res = Net::HTTP.start(url.host, url.port) {|http|
      http.get('/index.htm')
    }
    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!

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.

···

--
Posted via http://www.ruby-forum.com/.

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 = Net::HTTP.new(@hostname, 443)
    http.use_ssl = true
    http.start do |http|
      request = Net::HTTP::Post.new('index.html')
      request.set_content_type('content-type')
      puts 'set content-type done'
      request.basic_auth '', ''
      response = http.request(request, params["body"])
      puts 'making the request...'
      response.value
      case response
      when Net::HTTPSuccess, Net::HTTPRedirection
        puts 'success'
        @result = response.body
      else
        puts 'Error'
        response.error!
      end
    end

···

--
Posted via http://www.ruby-forum.com/.