我正在尝试使用 Rails 控制器发送发布请求,但是当我无法让控制器接受 use_ssl = true 时,我遇到了问题。这是我的代码
require "net/http"
require "uri"
params = {'requestId' => '1',
'merchantId' => 'merchantid'
'version' => '1.0.6',
'locale' => 'en_US',
'externalUserId' => '1234',
'partnerId' => 'partnerid',
'emailAddress' => 'test@email.com',
'deviceDTO' => "{'id' => '123123213', 'deviceType' => 'samsung'}",
'timestamp' => Time.now.strftime('%Y-%m-%dT%H:%M:%S.%L%z')
}
url = URI.parse('https://example.com')
http = Net::HTTP::Post.new(url.host)
http.set_form_data(params)
#http.use_ssl = true
#http.verify_mode = OpenSSL::SSL::VERIFY_PEER
res = Net::HTTP.start(url.hostname, url.port) do |h|
h.request(http)
h.use_ssl = true
h.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
错误是:
NoMethodError: undefined method `use_ssl=' for #<Net::HTTP::Post POST>
NoMethodError: undefined method `verify_mode=' for #<Net::HTTP::Post POST>
现在 UPD 错误
Errno::ECONNRESET: Connection reset by peer