Cannot get anything in https protocol with curl, httparty or net::http

好久不见. 提交于 2019-12-02 07:11:25

问题


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:


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


来源:https://stackoverflow.com/questions/8200048/cannot-get-anything-in-https-protocol-with-curl-httparty-or-nethttp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!