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

21,970

Solution 1

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"}

Solution 2

this error mostly get for using https

If it is https then

Please try this one

uri = URI.parse("https://84.38.185.251:9262/send")
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Get.new(uri.request_uri)
http.use_ssl = true  
response = http.request(request)

Note aditional

http.use_ssl = true

If it is not https

http.use_ssl = false

or you can add the condition

http.use_ssl = true if domain =~ /^https/

you can get more on this http://expressica.com/2012/02/10/eoferror-end-of-file-reached-issue-when-post-a-form-with-nethttp/

Share:
21,970
EgorkZe
Author by

EgorkZe

Updated on July 28, 2022

Comments

  • EgorkZe
    EgorkZe almost 2 years

    I am trying to get json form url :

    uri = URI.parse("http://84.38.185.251:9262/send")
    
    http = Net::HTTP.new(uri.host, uri.port)
    request = Net::HTTP::Get.new(uri.request_uri)
    
    response = http.request(request)
    
    response.code             # => 301
    response.body             # => The body (HTML, XML, blob, whatever)
    response["cache-control"] # => public, max-age=2592000
    puts response.body
    

    but i get an error :`EOFError (end of file reached): app/controllers/sensors_controller.rb:35:in sensinfo'

    sensors_controller.rb:35:

    response = http.request(request)
    

    What am i did wrong?