種類
- インスタンスメソッド (348)
- ライブラリ (12)
ライブラリ
-
net
/ http (348)
クラス
-
Net
:: HTTP (228) -
Net
:: HTTPResponse (108)
モジュール
-
Net
:: HTTPExceptions (12)
キーワード
- body (12)
-
close
_ on _ empty _ response= (12) - code (12)
- entity (12)
- get (24)
- get2 (24)
- head (12)
- head2 (24)
-
http
_ version (12) - msg (12)
- post (24)
- post2 (24)
-
read
_ body (24) -
request
_ get (24) -
request
_ head (24) -
request
_ post (24) - response (12)
-
send
_ request (12) - value (12)
検索結果
先頭5件
-
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(...