【问题标题】:Cannot get anything in https protocol with curl, httparty or net::http无法使用 curl、httparty 或 net::http 在 https 协议中获取任何内容
【发布时间】:2011-11-20 07:20:16
【问题描述】:

我无法使用 https 获取任何内容。

我无法获取以下内容:

curl -k https://graph.facebook.com

uri = URI('https://graph.facebook.com/davidarturo')
Net::HTTP.get(uri)

我明白了:

error: EOFError: end of file reached

httparty 和 https 也没有运气

【问题讨论】:

    标签: ruby-on-rails ruby curl https httparty


    【解决方案1】:

    当你使用'https'协议时,你必须明确告诉它以防使用net/http库:

    require 'net/http'
    
    uri = URI('https://graph.facebook.com/davidarturo')
    
    http = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = true if uri.scheme == 'https'
    
    http.start do |h|
      response = h.request Net::HTTP::Get.new(uri.request_uri)
      puts response.body if Net::HTTPSuccess
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-23
      • 2017-09-14
      • 1970-01-01
      • 2011-10-16
      • 2011-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多