るりまサーチ

最速Rubyリファレンスマニュアル検索!
99件ヒット [1-99件を表示] (0.184秒)
トップページ > クエリ:>[x] > 種類:インスタンスメソッド[x] > クエリ:e[x] > クエリ:get[x] > クラス:Net::HTTPResponse[x]

別のキーワード

  1. _builtin >
  2. bigdecimal >
  3. module >
  4. integer >
  5. float >

ライブラリ

キーワード

検索結果

Net::HTTPResponse#value -> nil (6232.0)

レスポンスが 2xx(成功)でなかった場合に、対応する 例外を発生させます。

...せます。

@raise HTTPError レスポンスが 1xx であるか、 net/http が知らない
種類のレスポンスである場合に発生します。
@raise HTTPRetriableError レスポンスが 3xx である場合に発生します。
@raise HTTPServerException レスポン...
...す。
@raise HTTPFatalError レスポンスが 5xx である場合に発生します。

//emlist[例 レスポンスが 2xx(成功)][ruby]{
require 'net/http'

uri = "http://www.example.com/index.html"
response = Net::HTTP.get_response(URI.parse(uri))
response.value # => nil
//}

//emlist[例 レ...
...スポンスが 2xx以外][ruby]{
require 'net/http'

uri = "http://www.example.com/invalid.html"
response = Net::HTTP.get_response(URI.parse(uri))
begin
response.value
rescue => e
e
.class # => Net::HTTPServerException
e
.message # => 404 "Not Found"
e
nd
//}...

Net::HTTPResponse#read_body {|str| .... } -> () (6226.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)
e
nd
e
nd
e
nd
e
nd
//}

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

Net::HTTPResponse#read_body(dest=nil) -> String|nil (6226.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)
e
nd
e
nd
e
nd
e
nd
//}

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

Net::HTTPResponse#code -> String (6208.0)

HTTP のリザルトコードです。例えば '302' などです。

...スオブジェクトがどのクラスのインスタンスかを
見ることでもレスポンスの種類を判別できます。

//emlist[例][ruby]{
require 'net/http'

uri = "http://www.example.com/index.html"
response = Net::HTTP.get_response(URI.parse(uri))
response.code # => "200"
//}...

Net::HTTPResponse#entity -> String | () | nil (6208.0)

エンティティボディを返します。

...

Net::HTTPResponse
#read_body をブロック付きで呼んだ場合には
このメソッドはNet::ReadAdapter のインスタンスを返しますが、
これは使わないでください。

e
ntity は obsolete です。

//emlist[例][ruby]{
require 'net/http'

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

絞り込み条件を変える

Net::HTTPResponse#http_version -> String (6208.0)

サーバがサポートしている HTTP のバージョンを文字列で返します。

...サーバがサポートしている HTTP のバージョンを文字列で返します。

//emlist[例][ruby]{
require 'net/http'

uri = "http://www.example.com/index.html"
response = Net::HTTP.get_response(URI.parse(uri))
response.http_version # => "1.1"
//}...

Net::HTTPResponse#message -> String (6208.0)

HTTP サーバがリザルトコードに付加して返すメッセージです。 例えば 'Not Found' などです。

...して返すメッセージです。
例えば 'Not Found' などです。

msg は obsolete です。使わないでください。

//emlist[例][ruby]{
require 'net/http'

uri = "http://www.example.com/index.html"
response = Net::HTTP.get_response(URI.parse(uri))
response.message # => "OK"
//}...

Net::HTTPResponse#body -> String | () | nil (3108.0)

エンティティボディを返します。

...

Net::HTTPResponse
#read_body をブロック付きで呼んだ場合には
このメソッドはNet::ReadAdapter のインスタンスを返しますが、
これは使わないでください。

e
ntity は obsolete です。

//emlist[例][ruby]{
require 'net/http'

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

Net::HTTPResponse#msg -> String (3108.0)

HTTP サーバがリザルトコードに付加して返すメッセージです。 例えば 'Not Found' などです。

...して返すメッセージです。
例えば 'Not Found' などです。

msg は obsolete です。使わないでください。

//emlist[例][ruby]{
require 'net/http'

uri = "http://www.example.com/index.html"
response = Net::HTTP.get_response(URI.parse(uri))
response.message # => "OK"
//}...