Skip to content

End of Life Ruby 3.2 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)

Posts data to a host; returns a Net::HTTPResponse object.

Argument url must be a URI; argument data must be a hash:

Example
_uri = uri.dup
_uri.path = '/posts'
data = {title: 'foo', body: 'bar', userId: 1}
res = Net::HTTP.post_form(_uri, data) # => #<Net::HTTPCreated 201 Created readbody=true>
puts res.body

Output:

Example
{
  "title": "foo",
  "body": "bar",
  "userId": "1",
  "id": 101
}
See also .post .proxy_class? .new .start also in 4.1 · 4.0 · 3.4 · 3.3 · 3.1 · 3.0