【问题标题】: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