D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
Net
/
HTTPHeader
/
Filename :
set_form-i.ri
back
Copy
U:RDoc::AnyMethod[iI" set_form:ETI"Net::HTTPHeader#set_form;TF:publico:RDoc::Markup::Document:@parts[%o:RDoc::Markup::Paragraph; [I">Stores form data to be used in a +POST+ or +PUT+ request.;To:RDoc::Markup::BlankLine o; ; [I"FThe form data given in +params+ consists of zero or more fields; ;TI"each field is:;T@o:RDoc::Markup::List: @type:BULLET:@items[o:RDoc::Markup::ListItem:@label0; [o; ; [I"A scalar value.;To;;0; [o; ; [I"A name/value pair.;To;;0; [o; ; [I"%An IO stream opened for reading.;T@o; ; [ I"$Argument +params+ should be an ;TI"B{Enumerable}[rdoc-ref:Enumerable@Enumerable+in+Ruby+Classes] ;TI"2(method <tt>params.map</tt> will be called), ;TI"#and is often an array or hash.;T@o; ; [I" First, we set up a request:;T@o:RDoc::Markup::Verbatim; [I"_uri = uri.dup ;TI"_uri.path ='/posts' ;TI"%req = Net::HTTP::Post.new(_uri) ;T:@format0o; ; [I")<b>Argument +params+ As an Array</b>;T@o; ; [I" When +params+ is an array, ;TI">each of its elements is a subarray that defines a field; ;TI"the subarray may contain:;T@o;; ;;[o;;0; [o; ; [I"One string:;T@o;; [I"/req.set_form([['foo'], ['bar'], ['baz']]) ;T;0o;;0; [o; ; [I"Two strings:;T@o;; [I"5req.set_form([%w[foo 0], %w[bar 1], %w[baz 2]]) ;T;0o;;0; [o; ; [I"5When argument +enctype+ (see below) is given as ;TI"$<tt>'multipart/form-data'</tt>:;T@o;; ;;[o;;0; [o; ; [I"7A string name and an IO stream opened for reading:;T@o;; [I"require 'stringio' ;TI"=req.set_form([['file', StringIO.new('Ruby is cool.')]]) ;T;0o;;0; [o; ; [I"5A string name, an IO stream opened for reading, ;TI":and an options hash, which may contain these entries:;T@o;; ;;[o;;0; [o; ; [I".+:filename+: The name of the file to use.;To;;0; [o; ; [I"<+:content_type+: The content type of the uploaded file.;T@o; ; [I" Example:;T@o;; [I"Ereq.set_form([['file', file, {filename: "other-filename.foo"}]] ;T;0o; ; [I"$The various forms may be mixed:;T@o;; [I"6req.set_form(['foo', %w[bar 1], ['file', file]]) ;T;0o; ; [I"'<b>Argument +params+ As a Hash</b>;T@o; ; [I"When +params+ is a hash, ;TI"Ceach of its entries is a name/value pair that defines a field:;T@o;; ;;[o;;0; [o; ; [I"The name is a string.;To;;0; [o; ; [I"The value may be:;T@o;; ;;[o;;0; [o; ; [I"+nil+.;To;;0; [o; ; [I"Another string.;To;;0; [o; ; [I"%An IO stream opened for reading ;TI"?(only when argument +enctype+ -- see below -- is given as ;TI"%<tt>'multipart/form-data'</tt>).;T@o; ; [I"Examples:;T@o;; [I"# Nil-valued fields. ;TI">req.set_form({'foo' => nil, 'bar' => nil, 'baz' => nil}) ;TI" ;TI"# String-valued fields. ;TI"8req.set_form({'foo' => 0, 'bar' => 1, 'baz' => 2}) ;TI" ;TI"# IO-valued field. ;TI"require 'stringio' ;TI"=req.set_form({'file' => StringIO.new('Ruby is cool.')}) ;TI" ;TI"# Mixture of fields. ;TI">req.set_form({'foo' => nil, 'bar' => 1, 'file' => file}) ;T;0o; ; [I"AOptional argument +enctype+ specifies the value to be given ;TI":to field <tt>'Content-Type'</tt>, and must be one of:;T@o;; ;;[o;;0; [o; ; [I"@<tt>'application/x-www-form-urlencoded'</tt> (the default).;To;;0; [o; ; [I"%<tt>'multipart/form-data'</tt>; ;TI"<see {RFC 7578}[https://www.rfc-editor.org/rfc/rfc7578].;T@o; ; [ I"6Optional argument +formopt+ is a hash of options ;TI".(applicable only when argument +enctype+ ;TI"(is <tt>'multipart/form-data'</tt>) ;TI",that may include the following entries:;T@o;; ;;[o;;0; [o; ; [I"N+:boundary+: The value is the boundary string for the multipart message. ;TI"4If not given, the boundary is a random string. ;TI"HSee {Boundary}[https://www.rfc-editor.org/rfc/rfc7578#section-4.1].;To;;0; [o; ; [I"E+:charset+: Value is the character set for the form submission. ;TI"SField names and values of non-file fields should be encoded with this charset.;T: @fileI"lib/net/http/header.rb;T:0@omit_headings_from_table_of_contents_below000[ I"F(params, enctype='application/x-www-form-urlencoded', formopt={});T@�FI"HTTPHeader;TcRDoc::NormalModule00