Ruby 4.1 リファレンスマニュアル

class Net::HTTPGenericRequest

[edit]

要約

Net::HTTPRequest のスーパークラスです。このクラスは直接は使わないでください。

Net::HTTPRequest のサブクラスを使ってください。

目次

インスタンスメソッド

継承しているメソッド

Net::HTTPHeaderから継承しているメソッド

インスタンスメソッド

body -> String[permalink][rdoc][edit]

サーバに送るリクエストのエンティティボディを返します。

例
require 'net/http'

uri = URI('http://www.example.com/index.html')
req = Net::HTTP::Post.new(uri.request_uri)
req.body = "Test Post Data"
p req.body # => "Test Post Data"

[SEE_ALSO] Net::HTTPGenericRequest#body=

body=(body)[permalink][rdoc][edit]

サーバに送るリクエストのエンティティボディを文字列で設定します。

[PARAM] body:
設定するボディを文字列で与えます。
例
require 'net/http'

uri = URI('http://www.example.com/index.html')
req = Net::HTTP::Post.new(uri.request_uri)
req.body = "Test Post Data" # => "Test Post Data"

[SEE_ALSO] Net::HTTPGenericRequest#body

body_exist? -> bool[permalink][rdoc][edit]

このメソッドは obsolete です。

Net::HTTPGenericRequest#response_body_permitted? の別名です。

body_stream -> objectRuby 1.9.3 から[permalink][rdoc][edit]
body_stream=(f)

サーバに送るリクエストのエンティティボディを IO オブジェクトなどのストリームで設定します。 f は read(size) メソッドが定義されている必要があります。

[PARAM] f:
エンティティボディのデータを得るストリームオブジェクトを与えます。
例
require 'net/http'

uri = URI('http://www.example.com/index.html')
post = Net::HTTP::Post.new(uri.request_uri)
File.open("/path/to/test", 'rb') do |f|
  # 大きなファイルを扱う際にメモリ消費を少なくできる
  post.body_stream = f
  post["Content-Length"] = f.size.to_s
  post.body_stream # => #<File:/path/to/test>
end
decode_content -> boolRuby 2.0.0 から[permalink][rdoc][edit]

リクエストヘッダフィールド Accept-Encoding: をユーザが明示的に設定・削除していないかどうかを表します。

ユーザが Accept-Encoding: を設定・削除していなければ真を、設定・削除していれば偽を返します。真の場合、Net::HTTP はレスポンスの Content-Encoding: に応じてボディを自動的に展開します (gzip/deflate の自動展開)。

例
require 'net/http'

uri = URI('http://www.example.com/index.html')
req = Net::HTTP::Get.new(uri)
p req['Accept-Encoding']    # => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3"
p req.decode_content         # => true
req['Accept-Encoding'] = 'foo'
p req.decode_content         # => false
req.delete('Accept-Encoding')
p req.decode_content         # => false

[SEE_ALSO] Net::HTTPResponse#decode_content

method -> String[permalink][rdoc][edit]

リクエストの HTTP メソッドを文字列で返します。

例
require 'net/http'

uri = URI('http://www.example.com/index.html')
req = Net::HTTP::Post.new(uri.request_uri)
p req.method # => "POST"
req = Net::HTTP::Get.new(uri.request_uri)
p req.method # => "GET"
path -> String[permalink][rdoc][edit]

リクエストする path を文字列で返します。

例
require 'net/http'

uri = URI('http://www.example.com/index.html')
req = Net::HTTP::Get.new(uri.request_uri)
p req.path # => "/index.html"
request_body_permitted? -> bool[permalink][rdoc][edit]

リクエストにエンティティボディを一緒に送ることが許されている HTTP メソッド (POST など)の場合真を返します。

例
require 'net/http'

uri = URI('http://www.example.com/index.html')
post = Net::HTTP::Post.new(uri.request_uri)
post.request_body_permitted?   # => true

head = Net::HTTP::Head.new(uri.request_uri)
p head.request_body_permitted? # => false
response_body_permitted? -> bool[permalink][rdoc][edit]

サーバからのレスポンスにエンティティボディを含むことが許されている HTTP メソッド (GET, POST など)の場合真を返します。

例
require 'net/http'

uri = URI('http://www.example.com/index.html')
post = Net::HTTP::Post.new(uri.request_uri)
post.response_body_permitted?   # => true

head = Net::HTTP::Head.new(uri.request_uri)
p head.response_body_permitted? # => false
uri -> URI | nilRuby 2.0.0 から[permalink][rdoc][edit]

リクエストの生成に使われた URI オブジェクトを返します。

リクエストをパスの文字列で生成した場合 (URI オブジェクトを使わなかった場合) は nil を返します。

例
require 'net/http'

uri = URI('http://www.example.com/index.html')
p Net::HTTP::Get.new(uri).uri            # => #<URI::HTTP http://www.example.com/index.html>
p Net::HTTP::Get.new('/index.html').uri  # => nil

[SEE_ALSO] Net::HTTPResponse#uri