@@ -74,13 +74,13 @@ class HTTPHeaderSyntaxError < StandardError; end
7474 #
7575 # === POST
7676 #
77- # uri = URI( 'http://www.example.com/search.cgi')
77+ # uri = 'http://www.example.com/search.cgi'
7878 # res = Net::HTTP.post_form(uri, 'q' => 'ruby', 'max' => '50')
7979 # puts res.body
8080 #
8181 # === POST with Multiple Values
8282 #
83- # uri = URI( 'http://www.example.com/search.cgi')
83+ # uri = 'http://www.example.com/search.cgi'
8484 # res = Net::HTTP.post_form(uri, 'q' => ['ruby', 'perl'], 'max' => '50')
8585 # puts res.body
8686 #
@@ -497,25 +497,26 @@ def HTTP.get_response(uri_or_host, path_or_headers = nil, port = nil, &block)
497497 end
498498 end
499499
500- # Posts data to the specified URI object .
500+ # Posts data to the specified URI.
501501 #
502502 # Example:
503503 #
504504 # require 'net/http'
505505 # require 'uri'
506506 #
507- # Net::HTTP.post URI( 'http://www.example.com/api/search') ,
507+ # Net::HTTP.post 'http://www.example.com/api/search',
508508 # { "q" => "ruby", "max" => "50" }.to_json,
509509 # "Content-Type" => "application/json"
510510 #
511511 def HTTP . post ( url , data , header = nil )
512+ url = URI ( url ) if url . is_a? ( String )
512513 start ( url . hostname , url . port ,
513514 :use_ssl => url . scheme == 'https' ) { |http |
514515 http . post ( url , data , header )
515516 }
516517 end
517518
518- # Posts HTML form data to the specified URI object .
519+ # Posts HTML form data to the specified URI.
519520 # The form data must be provided as a Hash mapping from String to String.
520521 # Example:
521522 #
@@ -529,10 +530,11 @@ def HTTP.post(url, data, header = nil)
529530 #
530531 # require 'net/http'
531532 #
532- # Net::HTTP.post_form URI( 'http://www.example.com/search.cgi') ,
533+ # Net::HTTP.post_form 'http://www.example.com/search.cgi',
533534 # { "q" => "ruby", "max" => "50" }
534535 #
535536 def HTTP . post_form ( url , params )
537+ url = URI ( url ) if url . is_a? ( String )
536538 req = Post . new ( url )
537539 req . form_data = params
538540 req . basic_auth url . user , url . password if url . user
0 commit comments