Eoferror: End of File Reached Issue With Net::Http

EOFError: end of file reached issue with Net::HTTP

If the URL is using https instead of http, you need to add the following line:

parsed_url = URI.parse(url)
http = Net::HTTP.new(parsed_url.host, parsed_url.port)
http.use_ssl = true

Note the additional http.use_ssl = true.

And the more appropriate code which would handle both http and https will be similar to the following one.

url = URI.parse(domain)
req = Net::HTTP::Post.new(url.request_uri)
req.set_form_data({'name'=>'Sur Max', 'email'=>'some@email.com'})
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = (url.scheme == "https")
response = http.request(req)

See more in my blog: EOFError: end of file reached issue when post a form with Net::HTTP.

EOFError (end of file reached) in Ruby on Rails with http.request

I think it is a some sort of bug; typhoeus seems to work:

require 'typhoeus'

response = Typhoeus.get("http://84.38.185.251:9262/send")
p response.body
#=> {"ids":"-1","data":{"temp":"nan","h":"-1"},"status":"255","voltage":"-1"}

ruby net/http: How to fix EOFError on HTTPS POST request

Due to my wrong guess.

Net::HTTP.new does not take any block, so the code below

Net::HTTP.new uri.host, uri.port do |http|
http.use_ssl = true
end.start ...

should be

(Net::HTTP.new uri.host, uri.port).tap do |http|
http.use_ssl = true
end.start ...

EOFError - end of file reached when using Zoho mail

I managed to solve the problem. I had to set the default address in application_mailer.rb file

default from: 'Business Name <info@mydomainname.com>'



Related Topics



Leave a reply



Submit