我在使用OpenSSL 1.1.1b(通过Homebrew安装),ruby 2.6.0(通过rvm安装)和HTTParty 0.16.4(通过gem / bundler安装)的MacBook(macOS 10.14.3)上。根据{{3}},应该可以下载网站的对等证书。但是,当我在计算机上尝试执行此操作时,它会失败:
require "httparty"
peer_cert = nil
HTTParty.get("https://www.example.com") do |fragment|
peer_cert ||= fragment.connection.peer_cert
end
p peer_cert
有错误
Traceback (most recent call last):
28: from tmp/test.rb:5:in `<main>'
27: from /Users/nicholas.chambers/.rvm/gems/ruby-2.6.0/gems/httparty-0.16.4/lib/httparty.rb:623:in `get'
26: from /Users/nicholas.chambers/.rvm/gems/ruby-2.6.0/gems/httparty-0.16.4/lib/httparty.rb:491:in `get'
25: from /Users/nicholas.chambers/.rvm/gems/ruby-2.6.0/gems/httparty-0.16.4/lib/httparty.rb:573:in `perform_request'
24: from /Users/nicholas.chambers/.rvm/gems/ruby-2.6.0/gems/httparty-0.16.4/lib/httparty/request.rb:146:in `perform'
23: from /Users/nicholas.chambers/.rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/net/http.rb:1470:in `request'
22: from /Users/nicholas.chambers/.rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/net/http.rb:920:in `start'
21: from /Users/nicholas.chambers/.rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/net/http.rb:1472:in `block in request'
20: from /Users/nicholas.chambers/.rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/net/http.rb:1479:in `request'
19: from /Users/nicholas.chambers/.rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/net/http.rb:1517:in `transport_request'
18: from /Users/nicholas.chambers/.rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/net/http/response.rb:165:in `reading_body'
17: from /Users/nicholas.chambers/.rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/net/http.rb:1518:in `block in transport_request'
16: from /Users/nicholas.chambers/.rvm/gems/ruby-2.6.0/gems/httparty-0.16.4/lib/httparty/request.rb:150:in `block in perform'
15: from /Users/nicholas.chambers/.rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/net/http/response.rb:204:in `read_body'
14: from /Users/nicholas.chambers/.rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/net/http/response.rb:283:in `read_body_0'
13: from /Users/nicholas.chambers/.rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/net/http/response.rb:264:in `inflater'
12: from /Users/nicholas.chambers/.rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/net/http/response.rb:293:in `block in read_body_0'
11: from /Users/nicholas.chambers/.rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/net/http/response.rb:405:in `read'
10: from /Users/nicholas.chambers/.rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/net/protocol.rb:163:in `read'
9: from /Users/nicholas.chambers/.rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/net/protocol.rb:488:in `<<'
8: from /Users/nicholas.chambers/.rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/net/protocol.rb:497:in `call_block'
7: from /Users/nicholas.chambers/.rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/net/http/response.rb:382:in `block in inflate_adapter'
6: from /Users/nicholas.chambers/.rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/net/http/response.rb:382:in `inflate'
5: from /Users/nicholas.chambers/.rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/net/http/response.rb:384:in `block (2 levels) in inflate_adapter'
4: from /Users/nicholas.chambers/.rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/net/protocol.rb:488:in `<<'
3: from /Users/nicholas.chambers/.rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/net/protocol.rb:497:in `call_block'
2: from /Users/nicholas.chambers/.rvm/gems/ruby-2.6.0/gems/httparty-0.16.4/lib/httparty/request.rb:152:in `block (2 levels) in perform'
1: from tmp/test.rb:6:in `block in <main>'
/Users/nicholas.chambers/.rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/delegate.rb:87:in `method_missing': undefined method `connection' for #<HTTParty::FragmentWithResponse:0x00007f9382035440> (NoMethodError)
我浏览了存储库中的未解决问题,并进行了一些谷歌搜索,但没有发现任何问题。我现在很茫然。任何帮助将不胜感激,谢谢!
更新: 尽管我想知道为什么HTTParty无法正常工作,但是this example可以做到。
答案 0 :(得分:1)
0.16.4
没有connection
Source
您所指的“示例”与其他更改相对应
因此,您似乎需要直接从github安装才能访问此功能,或者等待下一个版本发布。