るりまサーチ

最速Rubyリファレンスマニュアル検索!
66件ヒット [1-66件を表示] (0.036秒)

別のキーワード

  1. request new
  2. http request_get
  3. http request_put
  4. http request_post
  5. http request_head

ライブラリ

クラス

キーワード

検索結果

Net::HTTP#request_get(path, header = nil) -> Net::HTTPResponse (15139.0)

サーバ上の path にあるエンティティを取得します。 Net::HTTPResponse オブジェクトを返します。

...][ruby]{
# example
response = http.request_get('/index.html')
p response['content-type']
puts response.body # body is already read

# using block
http.request_get('/index.html') {|response|
p response['content-type']
response.read_body do |str| # read body now
print str
end
}
//...
...}

get2 は時代遅れなので使わないでください。

@see Net::HTTP#get, Net::HTTPResponse#read_body...

Net::HTTP#request_get(path, header = nil) {|response| .... } -> Net::HTTPResponse (15139.0)

サーバ上の path にあるエンティティを取得します。 Net::HTTPResponse オブジェクトを返します。

...][ruby]{
# example
response = http.request_get('/index.html')
p response['content-type']
puts response.body # body is already read

# using block
http.request_get('/index.html') {|response|
p response['content-type']
response.read_body do |str| # read body now
print str
end
}
//...
...}

get2 は時代遅れなので使わないでください。

@see Net::HTTP#get, Net::HTTPResponse#read_body...

Net::HTTPResponse#read_body {|str| .... } -> () (6139.0)

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

...度に結果取得][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.pars...
...ttp|
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
//}...
...ボディを文字列として
返します。また一度ブロックを与えてこのメソッドを呼んだ場合には、
次からは Net::ReadAdapter のインスタンスが返ってきますが、
その場合はそのオブジェクトは使わないでください。

dest は obsolete...

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

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

...度に結果取得][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.pars...
...ttp|
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
//}...
...ボディを文字列として
返します。また一度ブロックを与えてこのメソッドを呼んだ場合には、
次からは Net::ReadAdapter のインスタンスが返ってきますが、
その場合はそのオブジェクトは使わないでください。

dest は obsolete...

Net::HTTP#get2(path, header = nil) -> Net::HTTPResponse (39.0)

サーバ上の path にあるエンティティを取得します。 Net::HTTPResponse オブジェクトを返します。

...][ruby]{
# example
response = http.request_get('/index.html')
p response['content-type']
puts response.body # body is already read

# using block
http.request_get('/index.html') {|response|
p response['content-type']
response.read_body do |str| # read body now
print str
end
}
//...
...}

get2 は時代遅れなので使わないでください。

@see Net::HTTP#get, Net::HTTPResponse#read_body...

絞り込み条件を変える

Net::HTTP#get2(path, header = nil) {|response| .... } -> Net::HTTPResponse (39.0)

サーバ上の path にあるエンティティを取得します。 Net::HTTPResponse オブジェクトを返します。

...][ruby]{
# example
response = http.request_get('/index.html')
p response['content-type']
puts response.body # body is already read

# using block
http.request_get('/index.html') {|response|
p response['content-type']
response.read_body do |str| # read body now
print str
end
}
//...
...}

get2 は時代遅れなので使わないでください。

@see Net::HTTP#get, Net::HTTPResponse#read_body...