Feature #12375 ยป net_http_s_post.diff
lib/net/http.rb | ||
---|---|---|
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:
|
test/net/http/test_http.rb | ||
---|---|---|
end
|
||
end
|
||
def test_s_post
|
||
url = "http://#{config('host')}:#{config('port')}/"
|
||
res = Net::HTTP.post(
|
||
URI.parse(url),
|
||
"a=x")
|
||
assert_equal "application/x-www-form-urlencoded", res["Content-Type"]
|
||
assert_equal "a=x", res.body
|
||
res = Net::HTTP.post(
|
||
URI.parse(url),
|
||
"hello world",
|
||
"Content-Type" => "text/plain; charset=US-ASCII")
|
||
assert_equal "text/plain; charset=US-ASCII", res["Content-Type"]
|
||
assert_equal "hello world", res.body
|
||
end
|
||
def test_s_post_form
|
||
url = "http://#{config('host')}:#{config('port')}/"
|
||
res = Net::HTTP.post_form(
|