无法使用curl,httparty或net :: http获取https协议中的任何内容

时间:2011-11-20 07:20:17

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

我无法使用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

也没有运气

1 个答案:

答案 0 :(得分: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