@@ -74,13 +74,13 @@ class HTTPHeaderSyntaxError < StandardError; end
74
74
#
75
75
# === POST
76
76
#
77
- # uri = URI( 'http://www.example.com/search.cgi')
77
+ # uri = 'http://www.example.com/search.cgi'
78
78
# res = Net::HTTP.post_form(uri, 'q' => 'ruby', 'max' => '50')
79
79
# puts res.body
80
80
#
81
81
# === POST with Multiple Values
82
82
#
83
- # uri = URI( 'http://www.example.com/search.cgi')
83
+ # uri = 'http://www.example.com/search.cgi'
84
84
# res = Net::HTTP.post_form(uri, 'q' => ['ruby', 'perl'], 'max' => '50')
85
85
# puts res.body
86
86
#
@@ -497,25 +497,26 @@ def HTTP.get_response(uri_or_host, path_or_headers = nil, port = nil, &block)
497
497
end
498
498
end
499
499
500
- # Posts data to the specified URI object .
500
+ # Posts data to the specified URI.
501
501
#
502
502
# Example:
503
503
#
504
504
# require 'net/http'
505
505
# require 'uri'
506
506
#
507
- # Net::HTTP.post URI( 'http://www.example.com/api/search') ,
507
+ # Net::HTTP.post 'http://www.example.com/api/search',
508
508
# { "q" => "ruby", "max" => "50" }.to_json,
509
509
# "Content-Type" => "application/json"
510
510
#
511
511
def HTTP . post ( url , data , header = nil )
512
+ url = URI ( url ) if url . is_a? ( String )
512
513
start ( url . hostname , url . port ,
513
514
:use_ssl => url . scheme == 'https' ) { |http |
514
515
http . post ( url , data , header )
515
516
}
516
517
end
517
518
518
- # Posts HTML form data to the specified URI object .
519
+ # Posts HTML form data to the specified URI.
519
520
# The form data must be provided as a Hash mapping from String to String.
520
521
# Example:
521
522
#
@@ -529,10 +530,11 @@ def HTTP.post(url, data, header = nil)
529
530
#
530
531
# require 'net/http'
531
532
#
532
- # Net::HTTP.post_form URI( 'http://www.example.com/search.cgi') ,
533
+ # Net::HTTP.post_form 'http://www.example.com/search.cgi',
533
534
# { "q" => "ruby", "max" => "50" }
534
535
#
535
536
def HTTP . post_form ( url , params )
537
+ url = URI ( url ) if url . is_a? ( String )
536
538
req = Post . new ( url )
537
539
req . form_data = params
538
540
req . basic_auth url . user , url . password if url . user
0 commit comments