【问题标题】:Parsing HTTPS instead of HTTP in Rails在 Rails 中解析 HTTPS 而不是 HTTP
【发布时间】:2021-05-06 21:10:36
【问题描述】:

我知道如何使用 Net::HTTP 解析 HTTP 请求。你如何解析 HTTPS 请求?

我试过了,它说作为响应(其中一行):

<head><title>400 The plain HTTP request was sent to HTTPS port</title></head>

斯托克斯

已编辑:

所以要更详细地向您展示:

例如,这里是 HTTP API

https://xxxxx.info/merchant/balance?password=$main_password

如何使用 Net:http 来运行它?还是我用别的东西?

谢谢 斯托克斯

【问题讨论】:

  • 看起来请求来自 443 端口,但它是作为标准 http 请求而不是 https。

标签: ruby-on-rails https


【解决方案1】:

如果您向我们展示一些代码会有所帮助吗?

尝试设置这些属性

# assuming http is generated like this http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
# might need this as well? 
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

【讨论】:

    【解决方案2】:

    您可以通过在执行请求之前将use_ssl 设置为true 来实现。

    uri = URI(https://xxxxx.info/merchant/balance?password=$main_password)
    res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
      http.request(req)
    end
    puts res.body
    

    参考https://ruby-doc.org/stdlib-2.4.1/libdoc/net/http/rdoc/Net/HTTP.html#class-Net::HTTP-label-HTTPS

    【讨论】:

      猜你喜欢
      • 2011-05-03
      • 2019-11-09
      • 1970-01-01
      • 1970-01-01
      • 2015-08-04
      • 2021-05-28
      • 2022-12-18
      • 2019-02-27
      • 2017-05-19
      相关资源
      最近更新 更多