0
我想發送使用rails控制器的post請求,但是我遇到了問題,當我不能讓控制器接受use_ssl = true。 這裏是我的代碼沒有方法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' => '[email protected]',
'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
是你的Rails應用程序安裝在SSL模式下運行? –