ruby-on-rails – 带有http.request的Ruby on Rails中的EOFError(文件末尾)

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – 带有http.request的Ruby on Rails中的EOFError(文件末尾)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想获取json表单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

但我收到一个错误:`EOFError(文件结束):
app / controllers / sensors_controller.rb:35:在sensinfo’

sensors_controller.rb:35:

response = http.request(request)

我做错了什么?

解决方法

我认为这是一种某种错误; typhoeus似乎工作:
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"}
原文链接:https://www.f2er.com/ruby/267649.html

猜你在找的Ruby相关文章