diff options
author | aamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-04-20 16:53:27 +0000 |
---|---|---|
committer | aamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-04-20 16:53:27 +0000 |
commit | b6b8750a29313a817c34cad5cdf0eaeb66fee2a4 (patch) | |
tree | a8f916436dade34847393bb7bfaecf504259013b | |
parent | 514df9097eaca61ba9cddf1da6692af8be51ac2a (diff) | |
download | ruby-b6b8750a29313a817c34cad5cdf0eaeb66fee2a4.tar.gz |
* lib/net/http.rb: add rdoc.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8368 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | lib/net/http.rb | 61 |
2 files changed, 52 insertions, 13 deletions
@@ -1,3 +1,7 @@ +Thu Apr 21 01:53:09 2005 Minero Aoki <aamine@loveruby.net> + + * lib/net/http.rb: add rdoc. + Thu Apr 21 00:07:50 2005 Nobuyoshi Nakada <nobu@ruby-lang.org> * lib/mkmf.rb (create_makefile): support platforms have file separator diff --git a/lib/net/http.rb b/lib/net/http.rb index dd4c6b3140..5f40a47602 100644 --- a/lib/net/http.rb +++ b/lib/net/http.rb @@ -46,31 +46,66 @@ module Net # :nodoc: # # === Getting Document From WWW Server # - # (formal version) + # Example #1: Simple GET+print # # require 'net/http' - # Net::HTTP.start('www.example.com', 80) {|http| - # response = http.get('/index.html') - # puts response.body - # } + # Net::HTTP.get_print 'www.example.com', '/index.html' # - # (shorter version) + # Example #2: Simple GET+print by URL # # require 'net/http' - # Net::HTTP.get_print 'www.example.com', '/index.html' + # require 'uri' + # Net::HTTP.get_print URI.parse('http://www.example.com/index.html') # - # or + # Example #3: More generic GET+print # # require 'net/http' # require 'uri' - # Net::HTTP.get_print URI.parse('http://www.example.com/index.html') + # + # url = URI.parse('http://www.example.com/index.html') + # res = Net::HTTP.start(url.host, url.port) {|http| + # http.get('/index.html') + # } + # puts res.body + # + # Example #4: More generic GET+print + # + # 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 # # === Posting Form Data # # require 'net/http' - # Net::HTTP.start('some.www.server', 80) {|http| - # response = http.post('/cgi-bin/search.rb', 'query=ruby') - # } + # require 'uri' + # + # #1: Simple POST + # res = Net::HTTP.post_form(URI.parse('http://www.example.com/search.cgi'), + # {'q'=>'ruby', 'max'=>'50'}) + # puts res.body + # + # #2: POST with basic authentication + # res = Net::HTTP.post_form(URI.parse('http://jack:pass@www.example.com/todo.cgi'), + # {'from'=>'2005-01-01', 'to'=>'2005-03-31'}) + # puts res.body + # + # #3: Detailed control + # url = URI.parse('http://www.example.com/todo.cgi') + # req = Net::HTTP::Post.new(url.path) + # req.basic_auth 'jack', 'pass' + # req.set_form_data({'from'=>'2005-01-01', 'to'=>'2005-03-31'}, ';') + # res = Net::HTTP.new(url.host, url.port).start { http.request(req) } + # case res + # when Net::HTTPSuccess, Net::HTTPRedirection + # # OK + # else + # res.error! + # end # # === Accessing via Proxy # @@ -1467,7 +1502,7 @@ module Net # :nodoc: end - class HTTP + class HTTP # reopen class Get < HTTPRequest METHOD = 'GET' REQUEST_HAS_BODY = false |