红宝石NoMethodError(未定义的方法`set_body_internal')使用H

2019-10-18 07:38发布

我是新来的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

这里是我的输出:

Completed in 2ms (View: 1, DB: 72) | 200 OK [IP]
Hello...
Hello...1
Hello...2
tton]
  ←[4;36;1mSQL (188.1ms)←[0m   ←[0;1mSET SQL_AUTO_IS_NULL=0←[0m

Processing OpenidController#getOpenIdXRD (for 127.0.0.1 at 2013-06-25 20:28:04)
[GET]
  Parameters: {"user"=>""}

NoMethodError (undefined method `set_body_internal' for #):

Answer 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


文章来源: Ruby NoMethodError (undefined method `set_body_internal') with HTTP get