Object
Returns the entity body.
Calling this method a second or subsequent time will return the already read string.
http.request_get('/index.html') {|res| puts res.body } http.request_get('/index.html') {|res| p res.body.object_id # 538149362 p res.body.object_id # 538149362 }
# File net/http.rb, line 2403
def body
read_body()
end
Because it may be necessary to modify the body, Eg, decompression this method facilitates that.
# File net/http.rb, line 2409
def body=(value)
@body = value
end
# File net/http.rb, line 2276
def inspect
"#<#{self.class} #{@code} #{@message} readbody=#{@read}>"
end
Gets entity body. If the block given, yields it to block. The
body is provided in fragments, as it is read in from the socket.
Calling this method a second or subsequent time will return the already read string.
http.request_get('/index.html') {|res| puts res.read_body } http.request_get('/index.html') {|res| p res.read_body.object_id # 538149362 p res.read_body.object_id # 538149362 } # using iterator http.request_get('/index.html') {|res| res.read_body do |segment| print segment end }
# File net/http.rb, line 2371
def read_body(dest = nil, &block)
if @read
raise IOError, "#{self.class}\#read_body called twice" if dest or block
return @body
end
to = procdest(dest, block)
stream_check
if @body_exist
read_body_0 to
@body = to
else
@body = nil
end
@read = true
@body
end
For backward compatibility. To allow Net::HTTP 1.1 style assignment e.g.
response, body = Net::HTTP.get(....)
# File net/http.rb, line 2285
def to_ary
warn "net/http.rb: warning: Net::HTTP v1.1 style assignment found at #{caller(1)[0]}; use `response = http.get(...)' instead." if $VERBOSE
res = self.dup
class << res
undef to_ary
end
[res, res.body]
end
Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.
If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.
If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.
If you want to help improve the Ruby documentation, please see Improve the docs, or visit Documenting-ruby.org.