End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
class method
Net::HTTP.post_form
post_form(url, params)
lib/net/http.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.1.3/lib/net/http.rb, line 546
def HTTP.post_form(url, params)
req = Post.new(url)
req.form_data = params
req.basic_auth url.user, url.password if url.user
start(url.hostname, url.port,
:use_ssl => url.scheme == 'https' ) {|http|
http.request(req)
}
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:
Example
{ "cmd" => "search", "q" => "ruby", "max" => "50" }
This method also does Basic Authentication if and only if url.user exists. But userinfo for authentication is deprecated (RFC3986). So this feature will be removed.
Example:
Example
require 'net/http' Net::HTTP.post_form URI('http://www.example.com/search.cgi'), { "q" => "ruby", "max" => "50" }