1

我是 Ruby 编程的新手。我正在尝试使用 HTTP GET 请求获取 google XRDS,但遇到 NoMethodError (undefined method `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
吨]
  ←[4;36;1mSQL (188.1ms)←[0m ←[0;1mSET SQL_AUTO_IS_NULL=0←[0m

处理 OpenidController#getOpenIdXRD (for 127.0.0.1 at 2013-06-25 20:28:04)
[得到]
  参数:{"user"=>""}

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

1 回答 1

1

您实际上还没有为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
于 2013-09-04T11:16:40.713 回答