I got the error in Ruby. But it works in CURL.
Environment is rbenv
Ruby version : 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
curl -k https://xx:443/ -i \
-H "Accept: application/json" \
-H "Content-Type:application/json" \
-X POST -d @${1} https://xx:443/service/
Ruby
@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" => "[email protected]",
"Password" => "123456789"
}
req.body = to_send_body.to_json
res = @https.request(req)
data.json
{"ServiceID" : "SignUp","UserID" : "[email protected]","Password" : "123456789"}
UPDATE
I finished it by curb gem finally, but still failed on http way,
curb version
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