Method: Net::HTTPHeader#set_form
- Defined in:
- lib/net/http/header.rb
#set_form(params, enctype = 'application/x-www-form-urlencoded', formopt = {}) ⇒ Object
Set a HTML form data set. params is the form data set; it is an Array of Arrays or a Hash +enctype is the type to encode the form data set. It is application/x-www-form-urlencoded or multipart/form-data. formpot is an optional hash to specify the detail.
- boundary
-
the boundary of the multipart message
- charset
-
the charset of the message. All names and the values of non-file fields are encoded as the charset.
Each item of params is an array and contains following items:
name-
the name of the field
value-
the value of the field, it should be a String or a File
opt-
an optional hash to specify additional information
Each item is a file field or a normal field. If value is a File object or the opt have a filename key, the item is treated as a file field.
If Transfer-Encoding is set as chunked, this send the request in chunked encoding. Because chunked encoding is HTTP/1.1 feature, you must confirm the server to support HTTP/1.1 before sending it.
Example:
http.set_form([["q", "ruby"], ["lang", "en"]])
See also RFC 2388, RFC 2616, HTML 4.01, and HTML5
404 405 406 407 408 409 410 411 412 413 414 415 416 |
# File 'lib/net/http/header.rb', line 404 def set_form(params, enctype='application/x-www-form-urlencoded', formopt={}) @body_data = params @body = nil @body_stream = nil @form_option = formopt case enctype when /\Aapplication\/x-www-form-urlencoded\z/i, /\Amultipart\/form-data\z/i self.content_type = enctype else raise ArgumentError, "invalid enctype: #{enctype}" end end |