gpt4 book ai didi

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

转载 作者:数据小太阳 更新时间:2023-10-29 06:57:26 27 4
gpt4 key购买 nike

我正在尝试获取 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:in sensinfo'

传感器 Controller .rb:35:

response = http.request(request)

我做错了什么?

最佳答案

这个错误主要是因为使用 https

如果是https

请试试这个

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)

注意事项

http.use_ssl = true

如果不是https

http.use_ssl = false

或者你可以添加条件

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

你可以得到更多关于这个 https://web.archive.org/web/20140226183826/http://expressica.com/2012/02/10/eoferror-end-of-file-reached-issue-when-post-a-form-with-nethttp/

关于ruby-on-rails - Ruby on Rails 中带有 http.request 的 EOFError(到达文件末尾),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23080164/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com