Ruby 2.5.0 リファレンスマニュアル > ライブラリ一覧 > net/httpライブラリ > Net::HTTPクラス

class Net::HTTP

クラス・モジュールの継承リスト: Net::HTTP < Object < Kernel < BasicObject
aliases: HTTPSession

要約

HTTP のクライアントのためのクラスです。

特異メソッド

定義 説明
Proxy(address, port = 80) -> Class

Proxy 経由で http サーバに接続するためのクラスを作成し返します。

http_default_port -> Integer
default_port -> Integer

HTTP のデフォルトポート (80) を返します。

get(uri) -> String
get(host, path, port = 80) -> String

指定した対象に GET リクエストを送り、そのボディを文字列として返します。

get_print(uri) -> ()
get_print(host, path, port = 80) -> ()

指定した対象から HTTP でエンティティボディを取得し、 $stdout に出力します。

get_response(uri) -> Net::HTTPResponse
get_response(host, path = nil, port = nil) -> Net::HTTPResponse

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

https_default_port -> Integer

HTTPS のデフォルトポート (443) を返します。

version_1_1? -> false
is_version_1_1? -> false

何もしません。互換性のために残されており、常に false を返します。

version_1_2? -> true
is_version_1_2? -> true

何もしません。互換性のために残されており、常に true を返します。

new(address, port = 80, proxy_addr = :ENV, proxy_port = nil, proxy_user=nil, proxy_pass=nil, no_proxy=nil) -> Net::HTTP

新しい Net::HTTP オブジェクトを生成します。

post_form(uri, params) -> Net::HTTPResponse

URI で指定した対象に フォームのデータを HTTP で POST します。

proxy_address -> String|nil

自身が (Net::HTTP.Proxy によって作成された) プロクシ用のクラスならばプロクシのアドレスを返します。

proxy_class? -> bool

自身が (Net::HTTP.Proxy によって作成された) プロクシ用のクラスならば真を返し、そうでなければ偽を返します。

proxy_pass -> String|nil

自身が (Net::HTTP.Proxy によって作成された) プロクシ用のクラスならばプロクシ認証のパスワードを返します。

proxy_port -> Integer|nil

自身が (Net::HTTP.Proxy によって作成された) プロクシ用のクラスならばプロクシのポート番号を返します。

proxy_user -> String|nil

自身が (Net::HTTP.Proxy によって作成された) プロクシ用のクラスで、かつプロクシの認証を利用する場合はプロクシ認証のユーザ名を返します。

start(address, port = 80, proxy_addr = :ENV, proxy_port = nil, proxy_user=nil, proxy_pass=nil) -> Net::HTTP
start(address, port = 80, proxy_addr = :ENV, proxy_port = nil, proxy_user=nil, proxy_pass=nil) {|http| .... } -> object

新しい Net::HTTP オブジェクトを生成し、 TCP コネクション、 HTTP セッションを開始します。

version_1_2 -> true

何もしません。互換性のために残されており、常に true を返します。

インスタンスメソッド

定義 説明
started? -> bool
active? -> bool

HTTP セッションが開始されていたら真を返します。

address -> String

接続するアドレスを返します。

ca_file -> String | nil

信頼する CA 証明書ファイルのパスを返します。

ca_file=(path)

信頼する CA 証明書ファイルのパスを文字列で設定します。

ca_path -> String | nil

信頼する CA 証明書ファイルが存在するディレクトリを設定します。

ca_path=(path)

信頼する CA 証明書ファイルが存在するディレクトリを設定します。

cert -> OpenSSL::X509::Certificate | nil

クライアント証明書を返します。

cert=(certificate)

クライアント証明書を設定します。

cert_store -> OpenSSL::X509::Store | nil

接続相手の証明書の検証のために使う、信頼している CA 証明書を含む証明書ストアを返します。

cert_store=(store)

接続相手の証明書の検証のために使う、信頼している CA 証明書を含む証明書ストアを設定します。

ciphers -> String | [String] | nil

Net::HTTP#ciphers で設定した値を返します。

ciphers=(ciphers)

利用可能な共通鍵暗号を設定します。

close_on_empty_response -> bool

レスポンスがボディを持っていない場合にコネクションを閉じるかどうかを返します。

close_on_empty_response=(bool)

レスポンスがボディを持っていない場合にコネクションを閉じるかどうかを設定します。

continue_timeout -> Integer | nil

「100 Continue」レスポンスを待つ秒数を返します。

continue_timeout=(seconds)

「100 Continue」レスポンスを待つ秒数を指定します。

copy(path, initheader = nil) -> Net::HTTPResponse

サーバの path に COPY リクエストをヘッダを initheader として送ります。

delete(path, initheader = nil) -> Net::HTTPResponse

サーバの path に DELETE リクエストをヘッダを initheader として送ります。

finish -> ()

HTTP セッションを終了します。セッション開始前にこのメソッドが呼ばれた場合は例外 IOError を発生します。

get(path, header = nil, dest = nil) -> Net::HTTPResponse
get(path, header = nil, dest = nil) {|body_segment| .... } -> Net::HTTPResponse

サーバ上の path にあるエンティティを取得し、 Net::HTTPResponse のインスタンスとして返します。

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

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

head(path, header = nil) -> Net::HTTPResponse

サーバ上の path にあるエンティティのヘッダのみを取得します。 Net::HTTPResponse のインスタンスを返します。

request_head(path, header = nil) -> Net::HTTPResponse
request_head(path, header = nil) {|response| .... } -> Net::HTTPResponse
head2(path, header = nil) -> Net::HTTPResponse
head2(path, header = nil) {|response| .... } -> Net::HTTPResponse

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

keep_alive_timeout -> Integer

以前のリクエストで使ったコネクションの再利用(keep-alive)を許可する秒数を返します。

keep_alive_timeout=(seconds)

以前のリクエストで使ったコネクションの再利用(keep-alive)を許可する秒数を設定します。

key -> OpenSSL::PKey::PKey | nil

クライアント証明書の秘密鍵を返します。

key=(key)

クライアント証明書の秘密鍵を設定します。

local_host -> String | nil

接続に用いるローカルホスト名を返します。

local_host=(host)

接続に用いるローカルホスト名を指定します。

local_port -> nil | Integer | String

接続に用いるローカルポートを返します。

local_port=(port)

接続に用いるローカルポートを設定します。

lock(path, body, initheader = nil) -> Net::HTTPResponse

サーバの path に LOCK リクエストをヘッダを initheader, ボディを body として送ります。

mkcol(path, body, initheader = nil) -> Net::HTTPResponse

サーバの path に MKCOL リクエストをヘッダが initheader, ボディを body として送ります。

move(path, body, initheader = nil) -> Net::HTTPResponse

サーバの path に MOVE リクエストをヘッダが initheader, ボディを body として送ります。

open_timeout -> Integer|nil

接続時に待つ最大秒数を返します。

open_timeout=(seconds)

接続時に待つ最大秒数を設定します。

options(path, initheader = nil) -> Net::HTTPResponse

サーバの path に OPTIONS リクエストをヘッダが initheader として送り、レスポンスを Net::HTTPResponse のオブジェクトで返します。

patch(path, data, initheader=nil, dest=nil) -> Net::HTTPResponse
patch(path, data, initheader=nil, dest=nil) {|body_segment| ... } -> Net::HTTPResponse

サーバ上の path にあるエンティティに対し文字列 data を PATCH リクエストで送ります。

peer_cert -> OpenSSL::X509::Certificate | nil

サーバの証明書を返します。

port -> Integer

接続するポート番号を返します。

post(path, data, header = nil, dest = nil) -> Net::HTTPResponse
post(path, data, header = nil, dest = nil) {|body_segment| .... } -> Net::HTTPResponse

サーバ上の path にあるエンティティに対し文字列 data を POST で送ります。

request_post(path, data, header = nil) -> Net::HTTPResponse
request_post(path, data, header = nil) {|response| .... } -> Net::HTTPResponse
post2(path, data, header = nil) -> Net::HTTPResponse
post2(path, data, header = nil) {|response| .... } -> Net::HTTPResponse

サーバ上の path にあるエンティティに対し文字列 data を POST で送ります。返り値は Net::HTTPResponse のインスタンスです。

propfind(path, body, initheader = {'Depth' => '0'}) -> Net::HTTPResponse

サーバの path に PROPFIND リクエストをヘッダを initheader, ボディを body として送ります。

proppatch(path, body, initheader = nil) -> Net::HTTPResponse

サーバの path に PROPPATCH リクエストをヘッダを initheader, ボディを body として送ります。

proxy? -> bool

プロクシを介して接続するなら真を返します。

proxy_address -> String|nil
proxyaddr -> String|nil

プロクシ経由で接続する HTTP オブジェクトならプロクシのアドレスを返します。

proxy_address=(address)

プロクシのアドレス(ホスト名、IPアドレス)を指定します。

proxy_from_env=(boolean)

プロクシ情報を環境変数から得るかどうかを指定します。

proxy_from_env? -> bool

プロクシ情報を環境変数から得る場合に true を返します。

proxy_pass -> String|nil

プロクシ経由で接続し、さらにプロクシのユーザ認証をする HTTP オブジェクトなら認証のパスワードをを返します。

proxy_pass=(pass)

プロクシのユーザ認証のパスワードを設定します。

proxy_port -> Integer|nil
proxyport -> Integer|nil

プロクシのポート番号を返します。

proxy_port=(port)

プロクシのポート番号を設定します。

proxy_uri -> String|nil

このメソッドは内部用なので使わないでください。

proxy_user -> String|nil

プロクシ経由で接続し、さらにプロクシのユーザ認証をする HTTP オブジェクトなら認証のユーザ名をを返します。

proxy_user=(user)

プロクシのユーザ認証のユーザ名を設定します。

put(path, data, initheader = nil) -> Net::HTTPResponse

サーバ上の path にあるエンティティに対し文字列 data を PUT で送ります。

request_put(path, data, initheader = nil) -> Net::HTTPResponse
request_put(path, data, initheader = nil) {|response| .... } -> Net::HTTPResponse
put2(path, data, initheader = nil) -> Net::HTTPResponse
put2(path, data, initheader = nil) {|response| .... } -> Net::HTTPResponse

サーバ上の path にあるエンティティに対し文字列 data を PUT で送ります。

read_timeout -> Integer|nil

読みこみ(read(2)) 一回でブロックしてよい最大秒数を返します。

read_timeout=(seconds)

読みこみ(read(2)) 一回でブロックしてよい最大秒数を設定します。

request(request, data = nil) -> Net::HTTPResponse
request(request, data = nil) {|response| .... } -> Net::HTTPResponse

Net::HTTPRequest オブジェクト request をサーバに送信します。

send_request(name, path, data = nil, header = nil) -> Net::HTTPResponse

HTTP リクエストをサーバに送り、そのレスポンスを Net::HTTPResponse のインスタンスとして返します。

set_debug_output(io) -> ()

デバッグ出力の出力先を指定します。このメソッドは深刻なセキュリティホールの原因になるため、デバッグ以外では決して使わないでください。

ssl_timeout -> Integer | nil

SSL/TLS のタイムアウト秒数を返します。

ssl_timeout=(sec)

SSL/TLS のタイムアウト秒数を設定します。

ssl_version -> String | Symbol | nil

利用するプロトコルの種類を返します。

ssl_version=(ver)

利用するプロトコルの種類を指定します。

start -> self
start {|http| .... } -> object

TCP コネクションを張り、HTTP セッションを開始します。すでにセッションが開始していたら例外 IOError を発生します。

trace(path, initheader = nil) -> Net::HTTPResponse

サーバの path に TRACE リクエストをヘッダを initheader として送ります。

unlock(path, body, initheader = nil) -> Net::HTTPResponse

サーバの path に UNLOCK リクエストをヘッダを initheader, ボディを body として送ります。

use_ssl=(bool)

HTTP で SSL/TLS を使うかどうかを設定します。

use_ssl? -> bool

SSLを利用して接続する場合に真を返します。

verify_callback -> Proc

自身に設定されている検証をフィルタするコールバックを返します。

verify_callback=(proc)

検証をフィルタするコールバックを設定します。

verify_depth -> Integer

証明書チェイン上の検証する最大の深さを返します。

verify_depth=(depth)

証明書チェイン上の検証する最大の深さを設定します。

verify_mode -> Integer | nil

検証モードを返します。

verify_mode=(mode)

検証モードを設定します。

継承したメソッド

! != __id__ __send__ instance_eval instance_exec method_missing singleton_method_added singleton_method_removed singleton_method_undefined !~ <=> == === =~ _dump class clone define_singleton_method display enum_for eql? equal? extend freeze frozen? hash initialize initialize_copy inspect instance_of? instance_variable_defined? instance_variable_get instance_variable_set instance_variables is_a? itself marshal_dump marshal_load method methods nil? object_id pretty_inspect pretty_print pretty_print_cycle pretty_print_inspect pretty_print_instance_variables private_methods protected_methods psych_to_yaml public_method public_methods public_send remove_instance_variable respond_to? respond_to_missing? send singleton_class singleton_method singleton_methods taint tainted? tap to_a to_ary to_hash to_int to_io to_proc to_regexp to_s to_str trust untaint untrust untrusted? yield_self .yaml_tag ::ARGF ::ARGV ::DATA ::ENV ::FALSE ::NIL ::RUBY_COPYRIGHT ::RUBY_DESCRIPTION ::RUBY_ENGINE ::RUBY_ENGINE_VERSION ::RUBY_PATCHLEVEL ::RUBY_PLATFORM ::RUBY_RELEASE_DATE ::RUBY_REVISION ::RUBY_VERSION ::SCRIPT_LINES__ ::STDERR ::STDIN ::STDOUT ::TOPLEVEL_BINDING ::TRUE