代码之家  ›  专栏  ›  技术社区  ›  teddybear

鞋子gem支持HTTPS请求吗?

  •  1
  • teddybear  · 技术社区  · 7 年前

    我一直在研究如何使用Shoes GUI builder发出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'
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   teddybear    7 年前

    我想出来了。更新请求以剥离令牌,并将verify\u模式设置为 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
    
    推荐文章