获得“对等方重置连接";点击 Google Contacts API 时出错 [英] getting a "connection reset by peer" error when hitting Google Contacts API
本文介绍了获得“对等方重置连接";点击 Google Contacts API 时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 Google 通讯录 API 将 Google 通讯录拉入 Rails 应用程序.我已经完成了 Oauth2 握手,现在正在使用我的访问令牌请求受保护的资源.代码如下:
I'm trying to pull Google Contacts into a Rails application using the Google Contacts API. I've completed the Oauth2 handshake, and am now requesting the protected resource with my access token. Here is the code:
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)
推荐答案
您正在请求 HTTPS 资源,因此您的 GET 请求需要使用 SSL 加密.
You're requesting an HTTPS resource, so your GET request needs to use SSL encryption.
http://ruby-doc.org/stdlib-1.9.3/libdoc/net/http/rdoc/Net/HTTP.html#method-i-use_ssl-3F
所以你的最后一行应该是这样的:
So your last line should look like:
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)
这篇关于获得“对等方重置连接";点击 Google Contacts API 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文