带有HTTP get的Ruby NoMethodError(未定义的方法`set_body_internal’)

我是Ruby编程的新手。 我试图获得带有HTTP GET请求的谷歌XRDS,但是运行到NoMethodError(未定义的方法`set_body_internal’)错误。 以下是我的代码。 任何帮助深表感谢。

require "net/https" require "uri" class OpenidController < ApplicationController def getOpenIdXRD print "Hello...\n" uri = URI.parse("https://gmail.com/.well-known/host-meta") print "Hello...1\n" # Shortcut #response1 = Net::HTTP.get_response(uri) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE print "Hello...2\n" File response1 = http.request(request) print "Hello...3\n" response1.body response1.status # Will print response.body # Net::HTTP.get_print(uri) end end 

这是我的输出:

完成2ms(查看:1,DB:72)|  200 OK [IP]
你好...
你好...... 1
你好... 2
 tton]
   ←[4; 36; 1mSQL(188.1ms)←[0m←[0; 1mSET SQL_AUTO_IS_NULL = 0←[0m

处理OpenidController#getOpenIdXRD(2013.0-25 20:28:04为127.0.0.1)
 [得到]
  参数:{“user”=>“”}

 NoMethodError(#的未定义方法`set_body_internal'):

您实际上没有为request参数分配值…

 response1 = http.request(request) 

……还……

 File response1 

…那里没有多大意义 – 也许你想把结果写到文件中?

最后,如果你只是想做一个GET,基于此的东西应该适合你…

 url = " ... insert valid path here ..." res = Net::HTTP.start('... hostname here ...', 80) {|http| http.get(url) } puts res.body