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

C

Caleb Mei

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
 
R

rking

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
 
R

Robert Klemme

2007/8/10 said:
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!

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

Kind regards

robert
 
R

Ruby Rubyruby

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.
 
C

Caleb Mei

Thank you for all the help.

Resolved the issue by downgrading to 1.8.5. :) 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top