我在Ruby中遇到了错误。但它适用于CURL
。
环境为rbenv
Ruby版本:ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0]
error: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
curl -k https://xx:443/ -i \
-H "Accept: application/json" \
-H "Content-Type:application/json" \
-X POST -d @${1} https://xx:443/service/
@uri = URI.parse(server_url)
@https = Net::HTTP.new(@uri.host, @uri.port)
@https.use_ssl = true
req = Net::HTTP::Post.new(@uri.path, initheader = @header )
to_send_body = {
"ServiceID" => "SignUp",
"UserID" => "fs.test@dsd.com",
"Password" => "123456789"
}
req.body = to_send_body.to_json
res = @https.request(req)
{"ServiceID" : "SignUp","UserID" : "poc.test@123.com","Password" : "123456789"}
我终于通过curb gem完成了它,但仍然以http方式失败,
c = Curl::Easy.http_post("https://1xx.xx.x.2:443/service/", to_send_body.to_json
) do |curl|
curl.ssl_verify_peer = false
curl.headers['Accept'] = 'application/json'
curl.headers['Content-Type'] = 'application/json'
end
答案 0 :(得分:1)
curl中的-k
标志表示当证书无效时它仍将连接。要在ruby中完成相同的操作,请使用以下
@https = Net::HTTP.new(@uri.host, @uri.port)
@https.use_ssl = true
@https.verify_mode = OpenSSL::SSL::VERIFY_NONE