Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Net::HTTP#request_post
(::String path, ::String data, ?::Net::headers initheader) ?{ (::Net::HTTPResponse response) -> void } -> ::Net::HTTPResponse
request_post(path, data, initheader = nil) { |response| ... }
lib/net/http.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/lib/net/http.rb, line 2343
def request_post(path, data, initheader = nil, &block) # :yield: +response+
request Post.new(path, initheader), data, &block
end
Sends a POST request to the server; forms the response into a Net::HTTPResponse object.
The request is based on the Net::HTTP::Post object created from string path, string data, and initial headers hash initheader.
With no block given, returns the response object:
Example
http = Net::HTTP.new(hostname) http.post('/todos', 'xyzzy') # => #<Net::HTTPCreated 201 Created readbody=true>
With a block given, calls the block with the response body and returns the response object:
Example
http.post('/todos', 'xyzzy') do |res| p res end # => #<Net::HTTPCreated 201 Created readbody=true>
Output:
Example
"{\n \"xyzzy\": \"\",\n \"id\": 201\n}"
See also
#request_head
#request_query
#request_get
#response_body_encoding=
also in
4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0