Cannot get anything in https protocol with curl, h

2019-03-02 11:37发布

I am having trouble to get anything using https.

I can't fetch anything like:

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

or

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

I get:

error: EOFError: end of file reached

Also there is no luck with httparty and https

1条回答
放我归山
2楼-- · 2019-03-02 12:26

As you use 'https' protocol, you must explicitly tell about it in case of using net/http library:

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
查看更多
登录 后发表回答