Rest-Client gem RoR, Getting SSL wrong version 错误
Rest-Client gem RoR, Getting SSL wrong version error
我想构建一个 cli ruby 应用程序,它将请求发送到 Rails API 服务器。我想使用 rest-client gem 来做到这一点。每次我使用
RestClient.post
我收到以下错误
SSL_connect returned=1 errno=0 state=error: wrong version number (OpenSSL::SSL::SSLError)
我可以从控制台为 运行 做些什么吗?代码很简单,我只是想测试一下这个功能,所以别担心,这不是最终的。
我是运行宁rails6.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-client不想和我合作。谢谢 :D
您访问的端口 3000 可能只是 http://
而不是 https://
。使用 https://
访问普通 http://
端口将导致客户端将服务器 HTTP 错误消息(因为客户端发送的 TLS 握手的开始不是有效的 HTTP)错误地解释为 HTTPS,这可能导致奇怪的错误,例如无效的数据包长度或错误的版本号。
我想构建一个 cli ruby 应用程序,它将请求发送到 Rails API 服务器。我想使用 rest-client gem 来做到这一点。每次我使用
RestClient.post
我收到以下错误
SSL_connect returned=1 errno=0 state=error: wrong version number (OpenSSL::SSL::SSLError)
我可以从控制台为 运行 做些什么吗?代码很简单,我只是想测试一下这个功能,所以别担心,这不是最终的。
我是运行宁rails6.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-client不想和我合作。谢谢 :D
您访问的端口 3000 可能只是 http://
而不是 https://
。使用 https://
访问普通 http://
端口将导致客户端将服务器 HTTP 错误消息(因为客户端发送的 TLS 握手的开始不是有效的 HTTP)错误地解释为 HTTPS,这可能导致奇怪的错误,例如无效的数据包长度或错误的版本号。