0

我是红宝石新手。我有以下代码片段,它执行 GET 操作并检索我的 facebook 组的名称

def get_groups
  query=("SELECT gid,name FROM group where gid in(SELECT gid from group_member where uid=me)")
  uri=URI("https://graph.facebook.com/fql")
  params={'q'=>query,'access_token'=>TOKEN}
  uri.query=URI.encode_www_form(params)
  response=Net::HTTP.get_response(uri)
  result=json.loads(response.text)
  return result['data']
end

但是当我执行上面的代码时,我得到以下错误:

/usr/lib/ruby/1.9.1/net/protocol.rb:141:in `read_nonblock': Connection reset by peer (Errno::ECONNRESET)
    from /usr/lib/ruby/1.9.1/net/protocol.rb:141:in `rbuf_fill'
    from /usr/lib/ruby/1.9.1/net/protocol.rb:122:in `readuntil'
    from /usr/lib/ruby/1.9.1/net/protocol.rb:132:in `readline'
    from /usr/lib/ruby/1.9.1/net/http.rb:2562:in `read_status_line'
    from /usr/lib/ruby/1.9.1/net/http.rb:2551:in `read_new'
    from /usr/lib/ruby/1.9.1/net/http.rb:1319:in `block in transport_request'
    from /usr/lib/ruby/1.9.1/net/http.rb:1316:in `catch'
    from /usr/lib/ruby/1.9.1/net/http.rb:1316:in `transport_request'
    from /usr/lib/ruby/1.9.1/net/http.rb:1293:in `request'
    from /usr/lib/ruby/1.9.1/net/http.rb:1195:in `request_get'
    from /usr/lib/ruby/1.9.1/net/http.rb:455:in `block in get_response'
    from /usr/lib/ruby/1.9.1/net/http.rb:745:in `start'
    from /usr/lib/ruby/1.9.1/net/http.rb:454:in `get_response'
    from fb.rb:12:in `get_groups'
    from fb.rb:32:in `<main>'

我在这里犯了什么错误?

4

2 回答 2

2

我相信这里的问题是您正在使用 HTTP 库来访问 HTTPS 服务。这些是根本不同的事情。这是一个 HTTPS 示例:

require 'net/http'
require 'net/https'
http = Net::HTTP.new('www.example.com', 443)
http.use_ssl = true
http.ssl_version = :TLSv1
http.ciphers = "ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:-LOW"
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
req = Net::HTTP::Get.new('/', {'Content-Type' =>'application/json'})
http.start {|http| http.request(req) }
于 2014-11-21T20:53:45.163 回答
0

您似乎有 SSL 证书验证问题。尝试关闭 SSL 验证。

Net::HTTP.verify_mode = OpenSSL::SSL::VERIFY_NONE

如果以上对您有所帮助,则问题的根源可能是当前的 OpenSSL 安装。尝试将其更新到最新版本。

于 2013-09-27T13:46:17.430 回答