我正在向Web服務發送帶自定義標頭的請求。通過Net :: HTTP發送Ruby中的http發佈請求
require 'uri'
require 'net/http'
uri = URI("https://api.site.com/api.dll")
https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl = true
headers =
{
'HEADER1' => "VALUE1",
'HEADER2' => "HEADER2"
}
response = https.post(uri.path, headers)
puts response
它不工作,我收到的錯誤:我如何解決這個
/usr/lib/ruby/1.9.1/net/http.rb:1932:in `send_request_with_body': undefined method `bytesize' for #<Hash:0x00000001b93a10> (NoMethodError)
?
P.S. Ruby 1.9.3
那麼,這裏的工作代碼是什麼? – rh4games