類別 Net::HTTP::Post

用於表示 HTTP 方法 POST 的類別

require 'net/http'
uri = URI('http://example.com')
hostname = uri.hostname # => "example.com"
uri.path = '/posts'
req = Net::HTTP::Post.new(uri) # => #<Net::HTTP::Post POST>
req.body = '{"title": "foo","body": "bar","userId": 1}'
req.content_type = 'application/json'
res = Net::HTTP.start(hostname) do |http|
  http.request(req)
end

請參閱 要求標頭

屬性

相關

常數

METHOD
REQUEST_HAS_BODY
RESPONSE_HAS_BODY