Method: Gem::Net::HTTP#request_post

Defined in:
lib/rubygems/vendor/net-http/lib/net/http.rb

#request_post(path, data, initheader = nil, &block) ⇒ Object Also known as: post2

Sends a POST request to the server; forms the response into a Gem::Net::HTTPResponse object.

The request is based on the Gem::Net::HTTP::Post object created from string path, string data, and initial headers hash initheader.

With no block given, returns the response object:

http = Gem::Net::HTTP.new(hostname)
http.post('/todos', 'xyzzy')
# => #<Gem::Net::HTTPCreated 201 Created readbody=true>

With a block given, calls the block with the response body and returns the response object:

http.post('/todos', 'xyzzy') do |res|
  p res
end # => #<Gem::Net::HTTPCreated 201 Created readbody=true>

Output:

"{\n  \"xyzzy\": \"\",\n  \"id\": 201\n}"


2294
2295
2296
# File 'lib/rubygems/vendor/net-http/lib/net/http.rb', line 2294

def request_post(path, data, initheader = nil, &block) # :yield: +response+
  request Post.new(path, initheader), data, &block
end