るりまサーチ

最速Rubyリファレンスマニュアル検索!
360件ヒット [1-100件を表示] (0.065秒)
トップページ > クエリ:response=[x] > クエリ:net/http[x]

別のキーワード

  1. rss title=
  2. rss date=
  3. rss description=
  4. rss link=
  5. rss content=

ライブラリ

クラス

モジュール

キーワード

検索結果

<< 1 2 3 ... > >>

net/http (38060.0)

汎用データ転送プロトコル HTTP を扱うライブラリです。 実装は 2616 に基きます。

...y]{
require 'net/http'
print Net::HTTP.get('www.example.com', '/index.html')
//}

//emlist[例2: URI を使う][ruby]{
require 'net/http'
require 'uri'
print Net::HTTP.get(URI.parse('http://www.example.com/index.html'))
//}

//emlist[例3: より汎用的な例][ruby]{
require 'net/http'
require 'ur...
...{
require 'net/http'

url = URI.parse('http://www.example.com/index.html')
req = Net::HTTP::Get.new(url.path)
res = Net::HTTP.start(url.host, url.port) {|http|
http.request(req)
}
puts res.body
//}

==== フォームの情報を送信する (POST)

//emlist[例][ruby]{
require 'net/http'
require '...
...たらエラーにします。

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

def fetch(uri_str, limit = 10)
# You should choose better exception.
raise ArgumentError, 'HTTP redirect too deep' if limit == 0

response =
Net::HTTP.get_response(URI.parse(uri_str))
case response
when...

Net::HTTP#close_on_empty_response=(bool) (14100.0)

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

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


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

@see Net::HTTP#close_on_empty_response

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

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

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

@raise HTTPError レスポンスが 1xx であるか、 net/http が知らない
種類のレスポンスである場合に発生します。
@raise HTTPRetriableError レスポンスが 3xx...
...功)][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_respons...

Net::HTTP#get(path, header = nil, dest = nil) -> Net::HTTPResponse (8018.0)

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

...が [レスポンスオブジェクト, そのボディ] となります。

//emlist[例][ruby]{
# net/http version 1.1
response, body = http.get( '/index.html' )

# net/http version 1.2
response =
http.get('/index.html')

# compatible in both version
response , = http.get('/index.html')
response.b...

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

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

...が [レスポンスオブジェクト, そのボディ] となります。

//emlist[例][ruby]{
# net/http version 1.1
response, body = http.get( '/index.html' )

# net/http version 1.2
response =
http.get('/index.html')

# compatible in both version
response , = http.get('/index.html')
response.b...

絞り込み条件を変える

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

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

...

1.1 互換モードの場合は、レスポンスに応じて例外が発生します。

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

response =
nil
Net::HTTP.start('some.www.server', 80) {|http|
response =
http.head('/index.html')
}
p response['content-type']
//}

@see Net::HTTP#request_head...

Net::HTTPResponse#read_body {|str| .... } -> () (8018.0)

ブロックを与えなかった場合にはエンティティボディを 文字列で返します。 ブロックを与えた場合には エンティティボディを少しずつ取得して順次ブロックに 文字列で与えます。

...果取得][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:/...

Net::HTTPResponse#read_body(dest=nil) -> String|nil (8018.0)

ブロックを与えなかった場合にはエンティティボディを 文字列で返します。 ブロックを与えた場合には エンティティボディを少しずつ取得して順次ブロックに 文字列で与えます。

...果取得][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:/...

Net::HTTP#post(path, data, header = nil, dest = nil) -> Net::HTTPResponse (8012.0)

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

...ポンスオブジェクト, そのボディ] となります。

//emlist[例][ruby]{
# net/http version 1.1
response, body = http.post('/cgi-bin/search.rb', 'query=subject&target=ruby')

# version 1.2
response =
http.post('/cgi-bin/search.rb', 'query=subject&target=ruby')

# using block
File.open(...
<< 1 2 3 ... > >>