【问题标题】:Does the shoes gem support HTTPS requests?鞋子 gem 支持 HTTPS 请求吗?
【发布时间】:2018-04-26 17:59:01
【问题描述】:

我一直在寻找如何使用 Shoes GUI 构建器发出 HTTPS 请求,但我收到了 SSL_connnect 连接错误,我不确定该怎么做。

我在这个Gist做了一个测试应用

这是错误:

SSL_connect returned=1 errno=0 state=error: certificate verify failed
/Applications/Shoes.app/Contents/MacOS/lib/ruby/2.2.0/net/http.rb:923:in `connect'
/Applications/Shoes.app/Contents/MacOS/lib/ruby/2.2.0/net/http.rb:923:in `block in connect'
/Applications/Shoes.app/Contents/MacOS/lib/ruby/2.2.0/timeout.rb:73:in `timeout'
/Applications/Shoes.app/Contents/MacOS/lib/ruby/2.2.0/net/http.rb:923:in `connect'
/Applications/Shoes.app/Contents/MacOS/lib/ruby/2.2.0/net/http.rb:863:in `do_start'
/Applications/Shoes.app/Contents/MacOS/lib/ruby/2.2.0/net/http.rb:852:in `start'
/Applications/Shoes.app/Contents/MacOS/lib/ruby/2.2.0/net/http.rb:1375:in `request'
shoes.rb:17:in `request'
shoes.rb:54:in `block (3 levels) in <main>'
-e:1:in `call'

【问题讨论】:

  • 你也可以发布错误信息

标签: ruby shoes shoes-4


【解决方案1】:

我想通了。更新请求以剥离令牌并将 verify_mode 设置为 OpenSSL::SSL::VERIFY_NONE 解决了问题。

token = Base64.encode64("#{user}:#{pass}").strip
uri = URI("https://example.com/")

http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Get.new(uri.request_uri)
request["authorization"] = "Bearer #{token}"
request["Content-Type"] = "application/json"
response = http.request(request)

info(response.body)
response

【讨论】:

  • 有点违背了使用 SSL 的目的,对吧?
猜你喜欢
  • 2016-02-14
  • 1970-01-01
  • 2015-11-17
  • 2014-03-07
  • 1970-01-01
  • 2023-04-04
  • 2012-10-11
  • 2011-10-01
  • 1970-01-01
相关资源
最近更新 更多