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
Find Unused Code in a Rails App
How to Match Accented Characters With a Regex
One-Liner to Recursively List Directories in Ruby
Unzip (Zip, Tar, Tag.Gz) Files With Ruby
How to Install Rvm on Windows 7
What Does "≪≪-" Mean in Ruby
How to Use Gem to Install Rails on Ubuntu
Best Practices for New Rails Deployments on Linux
Rails Devise: User_Signed_In? Not Working
What Is the "Right" Way to Iterate Through an Array in Ruby
How to Remove a Key from Hash and Get the Remaining Hash in Ruby/Rails
Uninstall All Installed Gems, in Osx
How Do Rvm and Rbenv Actually Work
Ruby - Access Multidimensional Hash and Avoid Access Nil Object
Uninstalling All Gems Ruby 2.0.0
Correctly Doing Redirect_To :Back in Ruby on Rails When Referrer Is Not Available