Method: HTTPClient#post_content
- Defined in:
- lib/httpclient.rb
#post_content(uri, *args, &block) ⇒ Object
Posts a content.
- uri
-
a String or an URI object which represents an URL of web resource.
- body
-
a Hash or an Array of body part. e.g.
{ "a" => "b" } => 'a=b'Give an array to pass multiple value like
[["a", "b"], ["a", "c"]] => 'a=b&a=c'When you pass a File as a value, it will be posted as a multipart/form-data. e.g.
{ 'upload' => file }You can also send custom multipart by passing an array of hashes. Each part must have a :content attribute which can be a file, all other keys will become headers.
[{ 'Content-Type' => 'text/plain', :content => "some text" }, { 'Content-Type' => 'video/mp4', :content => File.new('video.mp4') }] => <Two parts with custom Content-Type header> - header
-
a Hash or an Array of extra headers. e.g.
{ 'Accept' => '*/*' }or
[['Accept', 'image/jpeg'], ['Accept', 'image/png']]. - &block
-
Give a block to get chunked message-body of response like
post_content(uri) { |chunked_body| ... }.Size of each chunk may not be the same.
post_content follows HTTP redirect status (see HTTP::Status.redirect?) internally and try to post the content to redirected URL. See redirect_uri_callback= how HTTP redirection is handled.
If you need to get full HTTP response including HTTP status and headers, use post method.
610 611 612 613 |
# File 'lib/httpclient.rb', line 610 def post_content(uri, *args, &block) body, header = keyword_argument(args, :body, :header) follow_redirect(:post, uri, nil, body, header || {}, &block).content end |