@@ -763,19 +763,38 @@ def set_content_type(type, params = {})
763763
764764 alias content_type = set_content_type
765765
766- # Set header fields and a body from HTML form data.
767- # +params+ should be an Array of Arrays or
768- # a Hash containing HTML form data.
769- # Optional argument +sep+ means data record separator.
766+ # Sets the request body to a URL-encoded string derived from argument +params+,
767+ # and sets request header field <tt>'Content-Type'</tt>
768+ # to <tt>'application/x-www-form-urlencoded'</tt>.
770769 #
771- # Values are URL encoded as necessary and the content-type is set to
772- # application/x-www-form-urlencoded
770+ # The resulting request is suitable for HTTP request +POST+ or +PUT+.
773771 #
774- # Example:
772+ # Argument +params+ must be suitable for use as argument +enum+ to
773+ # {URI.encode_www_form}[https://docs.ruby-lang.org/en/master/URI.html#method-c-encode_www_form].
774+ #
775+ # With only argument +params+ given,
776+ # sets the body to a URL-encoded string with the default separator <tt>'&'</tt>:
777+ #
778+ # req = Net::HTTP::Post.new('example.com')
779+ #
780+ # req.set_form_data(q: 'ruby', lang: 'en')
781+ # req.body # => "q=ruby&lang=en"
782+ # req['Content-Type'] # => "application/x-www-form-urlencoded"
783+ #
784+ # req.set_form_data([['q', 'ruby'], ['lang', 'en']])
785+ # req.body # => "q=ruby&lang=en"
786+ #
787+ # req.set_form_data(q: ['ruby', 'perl'], lang: 'en')
788+ # req.body # => "q=ruby&q=perl&lang=en"
789+ #
790+ # req.set_form_data([['q', 'ruby'], ['q', 'perl'], ['lang', 'en']])
791+ # req.body # => "q=ruby&q=perl&lang=en"
792+ #
793+ # With string argument +sep+ also given,
794+ # uses that string as the separator:
775795 #
776- # http.form_data = {"q" => "ruby", "lang" => "en"}
777- # http.form_data = {"q" => ["ruby", "perl"], "lang" => "en"}
778- # http.set_form_data({"q" => "ruby", "lang" => "en"}, ';')
796+ # req.set_form_data({q: 'ruby', lang: 'en'}, '|')
797+ # req.body # => "q=ruby|lang=en"
779798 #
780799 # Net::HTTPHeader#form_data= is an alias for Net::HTTPHeader#set_form_data.
781800 def set_form_data ( params , sep = '&' )
0 commit comments