我有工作就好打往非SSL的API的方法,但它给了我,每当我只请求HTTPS的API以下错误响应:
757: unexpected token at '400 Bad Request Bad Request
Your browser sent a request that this server could not understand.
Reason: You're speaking plain HTTP to an SSL-enabled server port.
Instead use the HTTPS scheme to access this URL, please.
该方法相当简单:
def my_service_api_call(path = nil, query = nil) my_service_api_key = ENV["MY_SERVICE_KEY"] api_path = "#{path}/?api_key=#{my_service_api_key}{query}" url = URI.parse(api_path) req = Net::HTTP::Get.new(api_path) res = Net::HTTP.start(url.host, url.port) { |http| http.request(req) } JSON.parse(res.body)["results"] end
这适用于http,但仅通过https进行故障转移.是否有相同的方式来进行HTTPS请求?