Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
Net::HTTPResponse#body
() -> ::String
body
lib/net/http/response.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.4.1/lib/net/http/response.rb, line 400
def body
read_body()
end
Returns the string response body; note that repeated calls for the unmodified body return a cached string:
Example
path = '/todos/1' Net::HTTP.start(hostname) do |http| res = http.get(path) p res.body p http.head(path).body # No body. end
Output:
Example
"{\n \"userId\": 1,\n \"id\": 1,\n \"title\": \"delectus aut autem\",\n \"completed\": false\n}" nil