Ruby on rails &引用;主机名与服务器证书“不匹配”;Mechanize和HttpParty中的错误

Ruby on rails &引用;主机名与服务器证书“不匹配”;Mechanize和HttpParty中的错误,ruby-on-rails,ruby,mechanize,httparty,Ruby On Rails,Ruby,Mechanize,Httparty,有时,当我访问带有HTTParty或Mechanize的网站时,我会遇到以下错误: hostname "www.example.com" does not match the server certificate 如果您使用open方法,我可以看出这一点,但我不确定如何利用上述gems 机械化的堆栈跟踪: agent = Mechanize.new agent.read_timeout = 180 agent.open_timeout = 1

有时,当我访问带有
HTTParty
Mechanize
的网站时,我会遇到以下错误:

hostname "www.example.com" does not match the server certificate
如果您使用
open
方法,我可以看出这一点,但我不确定如何利用上述gems

机械化的堆栈跟踪:

agent = Mechanize.new
agent.read_timeout              = 180
agent.open_timeout              = 180
agent.user_agent_alias          = 'Mac Safari'
agent.redirect_ok               = :all
agent.follow_meta_refresh       = :anywhere
agent.follow_meta_refresh_self  = true
agent.get("https://some-domain.com")
/home/me/.rbenv/versions/2.2.2/lib/ruby/2.2.0/openssl/ssl.rb:232:in `post_connection_check'
/home/me/.rbenv/versions/2.2.2/lib/ruby/2.2.0/net/http.rb:925:in `connect'
/home/me/.rbenv/versions/2.2.2/lib/ruby/2.2.0/net/http.rb:863:in `do_start'
/home/me/.rbenv/versions/2.2.2/lib/ruby/2.2.0/net/http.rb:858:in `start'
/home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/net-http-persistent-2.9.4/lib/net/http/persistent.rb:700:in `start'
/home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/net-http-persistent-2.9.4/lib/net/http/persistent.rb:965:in `reset'
/home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/net-http-persistent-2.9.4/lib/net/http/persistent.rb:628:in `connection_for'
/home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/net-http-persistent-2.9.4/lib/net/http/persistent.rb:994:in `request'
/home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/mechanize-2.7.4/lib/mechanize/http/agent.rb:267:in `fetch'
/home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/mechanize-2.7.4/lib/mechanize.rb:464:in `get'
HTTParty
的堆栈跟踪:

HTTParty.get("https://some-domain.com")
/home/me/.rbenv/versions/2.2.2/lib/ruby/2.2.0/openssl/ssl.rb:232:in `post_connection_check'
/home/me/.rbenv/versions/2.2.2/lib/ruby/2.2.0/net/http.rb:925:in `connect'
/home/me/.rbenv/versions/2.2.2/lib/ruby/2.2.0/net/http.rb:863:in `do_start'
/home/me/.rbenv/versions/2.2.2/lib/ruby/2.2.0/net/http.rb:852:in `start'
/home/me/.rbenv/versions/2.2.2/lib/ruby/2.2.0/net/http.rb:1375:in `request'
/home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/httparty-0.13.7/lib/httparty/request.rb:117:in `perform'
/home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/httparty-0.13.7/lib/httparty.rb:545:in `perform_request'
/home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/httparty-0.13.7/lib/httparty.rb:476:in `get'

对于Mechanize,应将verify SSL设置为none

agent = Mechanize.new
agent.verify_mode = OpenSSL::SSL::VERIFY_NONE
对于HTTParty,有
验证:
选项 看到这个问题了吗

如果您想进行常规设置,请使用以下肮脏技巧:

OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE

非常糟糕的建议;看见也许OP应该创建一个具有专有名称的证书。关于这一点,请看@jww是的,当然。但是OP要求解决Mechanize和HTTParty的问题。我已经提供了解决办法。这些都是权宜之计,而不是超级清晰的额外解决方案。有时问题出在服务器端(而不是客户端),您只能采取变通办法。这不是投否决票的原因,因为我已经提供了op要求的内容。我希望你能理解我的观点。OP想要设置VERIFY_NONE。我已经回答了。因此,请删除downvote。@jww如果您不拥有服务器,则无法创建证书。看起来OP的问题很多,这就是我对OP问题的理解。对我来说,你关于创建证书的评论与OPs问题无关。向下投票,因为问题是:我不拥有服务器。存在SSL问题。我想要那一页!甚至每个浏览器都允许您选择“访问网站!”当证书出现问题时。你只是得到了警告,但仍然有可能得到错误证书的页面。如果是这种情况,他不能控制服务器,那么他应该结束当前连接,并使用匿名Diffie Hellman回退到新连接。因为ADH和EC-ADH不需要服务器证书,所以它还可以在线路上保存字节。@jww所以请发布OP的答案,以便他可以完成任务。我不知道如何使用你的技巧。您能否提供Mechanize和/或HTTParty解决方案来获取证书不正确的页面?你投了反对票,所以请提供更好的解决方案。如果您没有更好的解决方案,那么为什么要拒绝投票?您应该创建一个具有专有名称的服务器证书。为此,请参见