Skip to content
instance method

Net::HTTPSession#request_post

request_post(path, data, initheader = nil) { |response| ... }

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}"