所以我刚刚创建了一个这样的控制器:
require 'net/http'
class HowdyController < ApplicationController
def show
url = URI.parse("http://google.com")
req = Net::HTTP::Get.new(url.path)
@resp = Net::HTTP.new(url.host, url.port).start {|http| http.request(req)}
end
end
我的路线是这样的:
get "howdy/show"
我的观点是这样的:
<h1>Howdy#show</h1>
<%= "The call to example.com returned this: #{@resp}" %>
但是当我去http://localhost:3000/howdy/show
我得到这个错误
HTTP 请求路径为空
我对 Net::HTTP 完全陌生,只是想创造一些简单的东西!