Method: Manticore::Client#post
- Defined in:
- lib/manticore/client.rb
#post(url, options = {}, &block) ⇒ Response
Perform a HTTP POST request
Examples:
Simple usage
body = client.post("http://example.com/some/resource", params: {foo: "bar"}, headers: {"X-Custom-Header" => "whee"}).body
Passing a block as the success handler:
body = client.post("http://example.com/some/resource", params: {foo: "bar"}, headers: {"X-Custom-Header" => "whee"}) {|response| response.body }
Explicit success handler:
body = client.post("http://example.com/some/resource", params: {foo: "bar"}, headers: {"X-Custom-Header" => "whee"}).
on_success {|response| response.body }
Parameters:
-
url
(String)
—
URL to request
- options (Hash) (defaults to: {})
Options Hash (options):
-
query
(Hash)
—
Hash of options to be added to the URL as part of the query string
-
params
(Hash)
—
Hash of options to pass as a request body. For GET, HEAD, and DELETE requests, :params will be treated as :query if :query is not present.
-
headers
(Hash)
—
Hash of options to pass as additional request headers
-
proxy
(String)
—
Proxy host in form: proxy.org:1234
-
proxy
(Hash)
—
Proxy host in form: ‘proxy.org’[, port: 80[, scheme: ‘http’]]
-
proxy
(URI)
—
Proxy host as a URI object
-
connect_timeout
(Float)
—
Request-specific connect timeout (in seconds)
-
socket_timeout
(Float)
—
Request-specific socket timeout (in seconds)
-
request_timeout
(Float)
—
Request-specific request timeout (in seconds)
-
max_redirects
(Integer)
—
Request-specific maximum redirect limit
-
follow_redirects
(Boolean)
—
Specify whether this request should follow redirects
-
auth
(Hash)
—
Specify authentication for the request
-
auth[:user]
(String)
—
Username to auth with
-
auth[:password]
(String)
—
Password to auth with
-
auth[:eager]
(Boolean)
—
Eagerly offer the Authorization header before the server challenges for it. You should not use this unless you know you specifically need it, as misuse of it can leak user credentials.
-
body
(String)
—
Body to pass with the request
Returns:
- (Response)
Raises:
-
(Manticore::Timeout)
—
on socket, connection, or response timeout
-
(Manticore::SocketException)
—
on internal socket exception (ie, unexpected socket closure)
-
(Manticore::ClientProtocolException)
—
on protocol errors such as an SSL handshake failure or connection exception
-
(Manticore::ResolutionFailure)
—
on DNS resolution failure
283 284 285 |
# File 'lib/manticore/client.rb', line 283 def post(url, options = {}, &block) request HttpPost, url, options, &block end |