るりまサーチ

最速Rubyリファレンスマニュアル検索!
158件ヒット [1-100件を表示] (0.106秒)
トップページ > クエリ:i[x] > クエリ:h[x] > クエリ:get_response[x]

別のキーワード

  1. _builtin to_h
  2. env to_h
  3. hash to_h
  4. enumerable to_h
  5. array to_h

ライブラリ

クラス

モジュール

キーワード

検索結果

<< 1 2 > >>

Net::HTTP.get_response(host, path = nil, port = nil) -> Net::HTTPResponse (21402.0)

指定した対象に GET リクエストを送り、そのレスポンスを Net::HTTPResponse として返します。

...::HTTPResponse として返します。

対象の指定方法は URI で指定するか、
(host, path, port) で指定するかのいずれかです。

@param uri データの取得対象を URI で指定します。
@param host 接続先のホストを文字列で指定します。
@param path...
...データの存在するパスを文字列で指定します。
@param port 接続するポートを整数で指定します。
@see Net::HTTP#get...

Net::HTTP.get_response(uri) -> Net::HTTPResponse (21302.0)

指定した対象に GET リクエストを送り、そのレスポンスを Net::HTTPResponse として返します。

...::HTTPResponse として返します。

対象の指定方法は URI で指定するか、
(host, path, port) で指定するかのいずれかです。

@param uri データの取得対象を URI で指定します。
@param host 接続先のホストを文字列で指定します。
@param path...
...データの存在するパスを文字列で指定します。
@param port 接続するポートを整数で指定します。
@see Net::HTTP#get...

Net::HTTPResponse#http_version -> String (15206.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::HTTPHeader#main_type -> String|nil (9206.0)

"text/html" における "text" のようなタイプを表す 文字列を返します。

..."text/html" における "text" のようなタイプを表す
文字列を返します。

Content-Type: ヘッダフィールドが存在しない場合には nil を返します。

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

uri = URI.parse('http://www.example.com/index.html')
res = Net::HTTP.get_r...
...esponse(uri)
res.main_type # => "text"
//}...

Net::HTTPHeader#get_fields(key) -> [String] (9106.0)

key ヘッダフィールドの値 (文字列) を配列で返します。

...key ヘッダフィールドの値 (文字列) を配列で返します。

たとえばキー 'content-length' に対しては ['2048'] のような
文字列が得られます。一種類のヘッダフィールドが一つのヘッダの中
に複数存在することがありえます。
key は...
...ール名を文字列で与えます。

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

uri = URI.parse('http://www.example.com/index.html')
res = Net::HTTP.get_response(uri)
res.get_fields('accept-ranges') # => ["none"]
//}

@see Net::HTTPHeader#[] , Net::HTTPHeader#[]=,
Net::HTTPHeader#add_field...

絞り込み条件を変える

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

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

...nil を返します。

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

entity は obsolete です。

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

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

Net::HTTPExceptions#response -> Net::HTTPResponse (6106.0)

例外の原因となったレスポンスオブジェクトを返します。

...レスポンスオブジェクトを返します。

//emlist[例][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.response # => #<Net::HTTPNotFound 404 Not Found readbody=true>
end
//}...

Net::HTTPResponse#read_body(dest=nil) -> String|nil (3212.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 ブロック...
...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 で少しずつ読み書き。メモリ消費が少ない。
h
ttp....
...request_get(uri.path) do |response|
response.read_body do |s|
f.write(s)
end
end
end
end
//}

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

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

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

...nil を返します。

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

entity は obsolete です。

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

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

Net::HTTPResponse#value -> nil (3112.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"
end
//}...

絞り込み条件を変える

<< 1 2 > >>