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:inrbuf_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

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

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.host, 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

robert

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

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