Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 272
EgorkZe Avatar asked Apr 15 '14 09:04

EgorkZe


1 Answers

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/

like image 183
Rajarshi Das Avatar answered Oct 03 '22 20:10

Rajarshi Das