问题
I am new to Ruby programming. I am trying to get the google XRDS with HTTP GET request, but running in to the NoMethodError (undefined method `set_body_internal') Error. Below is my code. Any help is much appreciated.
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
Here is my output:
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 #):
回答1:
You haven't actually assigned a value to the request
parameter ...
response1 = http.request(request)
... also ...
File response1
... doesn't make much sense there - perhaps you want to write the result to a File?
Lastly, if you simply want to do a GET, something based on this should work for you ...
url = " ... insert valid path here ..."
res = Net::HTTP.start('... hostname here ...', 80) {|http|
http.get(url)
}
puts res.body
来源:https://stackoverflow.com/questions/17309815/ruby-nomethoderror-undefined-method-set-body-internal-with-http-get