クラス
-
Net
:: HTTPGenericRequest (33) -
Net
:: HTTPResponse (22) - OptionParser (22)
-
URI
:: Generic (22) -
URI
:: HTTP (11)
キーワード
-
body
_ stream (11) -
body
_ stream= (11) -
program
_ name (11) -
program
_ name= (11) -
read
_ body (22) -
request
_ uri (11) - select (11)
検索結果
先頭5件
-
URI
:: Generic # path -> String | nil (18166.0) -
自身の path を文字列で返します。設定されていない場合は nil を返します。
...自身の path を文字列で返します。設定されていない場合は nil を返します。
require 'uri'
p URI.parse('http://example.com/hoge').path #=> "/hoge"
p URI.parse('http://example.com').path #=> ""
p URI.parse('mailto:nospam@localhost').path #=> n......il
p URI('ftp://example.com/foo').path #=> 'foo'
p URI('ftp://example.com/%2Ffoo').path #=> '/foo'... -
Net
:: HTTPGenericRequest # path -> String (18130.0) -
リクエストする path を文字列で返します。
...リクエストする path を文字列で返します。
//emlist[例][ruby]{
require 'net/http'
uri = URI.parse('http://www.example.com/index.html')
req = Net::HTTP::Get.new(uri.request_uri)
req.path # => "/index.html"
//}... -
OptionParser
# program _ name -> String (3007.0) -
プログラムの名前を文字列で返します。
...字列で返します。
デフォルトは $0 が使われます。
@return プログラムの名前を文字列で返します。
//emlist[例][ruby]{
require "optparse"
OptionParser.new do |opts|
p $0 # => /path/to/filename.rb
p opts.program_name # => filename
end
//}... -
OptionParser
# program _ name=(name) (3007.0) -
プログラムの名前を文字列で指定します。
...す。
@param name プログラムの名前を文字列で指定します。
//emlist[例][ruby]{
require "optparse"
OptionParser.new do |opts|
$0 # => /path/to/filename.rb
opts.program_name # => filename
opts.program_name = 'test' # => "test"
opts.program... -
URI
:: HTTP # request _ uri -> String (51.0) -
自身の「path + '?' + query」を文字列で返します。 query が nil である場合は、自身の path を返します。
...自身の「path + '?' + query」を文字列で返します。
query が nil である場合は、自身の path を返します。
path が空である場合には、path は「'/'」であるとします。
例:
require 'uri'
u = URI.parse("http://example.com/search?q=xxx")
p u.request_u... -
Net
:: HTTPResponse # read _ body {|str| . . . . } -> () (31.0) -
ブロックを与えなかった場合にはエンティティボディを 文字列で返します。 ブロックを与えた場合には エンティティボディを少しずつ取得して順次ブロックに 文字列で与えます。
...onse(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.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
:: HTTPResponse # read _ body(dest=nil) -> String|nil (31.0) -
ブロックを与えなかった場合にはエンティティボディを 文字列で返します。 ブロックを与えた場合には エンティティボディを少しずつ取得して順次ブロックに 文字列で与えます。
...onse(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.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
:: HTTPGenericRequest # body _ stream -> object (19.0) -
サーバに送るリクエストのエンティティボディを IO オブジェクトなどのストリームで設定します。 f は read(size) メソッドが定義されている必要があります。
....parse('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
end
post.body_stream # => #<File:/path... -
Net
:: HTTPGenericRequest # body _ stream=(f) (19.0) -
サーバに送るリクエストのエンティティボディを IO オブジェクトなどのストリームで設定します。 f は read(size) メソッドが定義されている必要があります。
....parse('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
end
post.body_stream # => #<File:/path... -
URI
:: Generic # select(*components) -> [String] (13.0) -
指定された components に対応する構成要素を文字列の配列として返します。
...字列の配列として返します。
@param components 構成要素名をシンボルで指定します。
例:
require 'uri'
uri = URI.parse('http://myuser:mypass@my.example.com/test.rbx')
p uri.select(:userinfo, :host, :path)
# => ["myuser:mypass", "my.example.com", "/test.rbx"]...