我想构建一个cli应用程序,它向Rails API服务器发送请求。我想用rest客户端的宝石来做这个。每次我用
RestClient.post 我得到以下错误
SSL_connect returned=1 errno=0 state=error: wrong version number (OpenSSL::SSL::SSLError)我能为它在控制台上运行做些什么吗?代码很简单,我只是想测试一下这个特性,所以别担心,这还不是最终的。
我正在运行rails 6.0.3和ruby2.6.3。
require "tty-prompt"
prompt = TTY::Prompt.new
require 'rest-client'
if prompt.yes? "Do you have an account ?"
email = prompt.ask('What is your email?') do |q|
q.validate(/\A\w+@\w+\.\w+\Z/, 'Invalid email address')
end
pass = prompt.mask('password:')
puts email
puts pass
RestClient.post "https://localhost:3000/auth/sign_in", "email: #{email},password:#{pass}"
puts response.code
else
RestClient.post "https://localhost:3000/auth", "email: #{email},password:#{pass}"
end我想让cli应用程序向API发送一个请求,仅此而已,rest客户端不愿与我合作。谢谢:D
发布于 2019-09-21 22:18:49
您访问的端口3000很可能只是http://而不是https://。使用http://访问普通https://端口将导致客户端将服务器HTTP错误消息(因为客户端发送的TLS握手开始无效)错误地解释为HTTPS,这可能导致诸如无效数据包长度或版本号等奇怪的错误。
https://stackoverflow.com/questions/58044307
复制相似问题