【问题标题】:getting a "connection reset by peer" error when hitting Google Contacts API访问 Google Contacts API 时出现“对等连接重置”错误
【发布时间】:2012-02-17 23:27:10
【问题描述】:

我正在尝试使用 Google Contacts API 将 Google Contacts 拉入 Rails 应用程序。我已经完成了 Oauth2 握手,现在正在使用我的访问令牌请求受保护的资源。代码如下:

uri = URI('https://www.google.com/m8/feeds/contacts/default/full')
params = { :client_id => APP_CONFIG[:google_api_client_id],
           :access_token => auth.access_token,
           "max-results".to_sym => max_results
         }

uri.query = URI.encode_www_form(params)
res = Net::HTTP.get_response(uri)

【问题讨论】:

    标签: ruby-on-rails ruby api http


    【解决方案1】:

    您正在请求 HTTPS 资源,因此您的 GET 请求需要使用 SSL 加密。

    http://ruby-doc.org/stdlib-1.9.3/libdoc/net/http/rdoc/Net/HTTP.html#method-i-use_ssl-3F

    所以你的最后一行应该是这样的:

      http = Net::HTTP.new(uri.host, uri.port)
      http.use_ssl = true
      http.verify_mode = OpenSSL::SSL::VERIFY_NONE # You should use VERIFY_PEER in production
      request = Net::HTTP::Get.new(uri.request_uri)
      res = http.request(request)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-05
      • 1970-01-01
      • 2023-03-09
      • 1970-01-01
      • 2014-01-31
      • 2015-04-07
      • 2020-07-07
      • 2012-03-06
      相关资源
      最近更新 更多