aboutsummaryrefslogtreecommitdiffstats
path: root/lib/net
diff options
context:
space:
mode:
authorshugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-11-05 14:39:06 +0000
committershugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-11-05 14:39:06 +0000
commit4fc86dcb6687ba7b27f3ef1bc2d26fc541f8177f (patch)
tree979b1c12b8922d31efdd2133420862a089289001 /lib/net
parent59806dd439f512d6d5b40ea191a224d3198c9042 (diff)
downloadruby-4fc86dcb6687ba7b27f3ef1bc2d26fc541f8177f.tar.gz
* lib/net/http.rb (Net::HTTP.post): new convenience method to send a POST request.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56597 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/net')
-rw-r--r--lib/net/http.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/net/http.rb b/lib/net/http.rb
index 6031bcaaeb..d68d2c740e 100644
--- a/lib/net/http.rb
+++ b/lib/net/http.rb
@@ -489,6 +489,24 @@ module Net #:nodoc:
end
end
+ # Posts data to the specified URI object.
+ #
+ # Example:
+ #
+ # require 'net/http'
+ # require 'uri'
+ #
+ # Net::HTTP.post URI('http://www.example.com/api/search'),
+ # { "q" => "ruby", "max" => "50" }.to_json,
+ # "Content-Type" => "application/json"
+ #
+ def HTTP.post(url, data, header = nil)
+ start(url.hostname, url.port,
+ :use_ssl => url.scheme == 'https' ) {|http|
+ http.post(url.path, data, header)
+ }
+ end
+
# Posts HTML form data to the specified URI object.
# The form data must be provided as a Hash mapping from String to String.
# Example: