るりまサーチ

最速Rubyリファレンスマニュアル検索!
11件ヒット [1-11件を表示] (0.092秒)
トップページ > クエリ:i[x] > クエリ:html[x] > クエリ:request_get[x] > クラス:Net::HTTPResponse[x]

別のキーワード

  1. cgi/html element_init
  2. cgi/html doctype
  3. cgi/html form
  4. cgi/html multipart_form
  5. cgi/html reset

ライブラリ

検索結果

Net::HTTPResponse#read_body(dest=nil) -> String|nil (225.0)

ブロックを与えなかった場合にはエンティティボディを 文字列で返します。 ブロックを与えた場合には エンティティボディを少しずつ取得して順次ブロックに 文字列で与えます。

...い場合には nil を返します。

//emlist[例1 ブロックを与えずに一度に結果取得][ruby]{
require 'net/http'

uri = "http://www.example.com/index.html"
response = Net::HTTP.get_response(URI.parse(uri))
response.read_body[0..10] # => "<!doctype h"
//}

//emlist[例2 ブロック...
...大きいファイルを取得][ruby]{
require 'net/http'

uri = URI.parse('http://www.example.com/path/to/big.file')
Net::HTTP.start(uri.host, uri.port) do |http|
File.open("/path/to/big.file", "w") do |f|
# Net::HTTP#request_get Net::HTTPResponse#read_body で少しずつ読み書き。...
...メモリ消費が少ない。
http.request_get(uri.path) do |response|
response.read_body do |s|
f.write(s)
end
end
end
end
//}

一度ブロックを与えずにこのメソッドを呼んだ場合には、
次からはすでに読みだしたボディを文字列と...