How do I make HTTParty ignore SSL?

半城伤御伤魂 提交于 2019-11-28 07:55:20

In the latest HTTParty, you can use the verify option to disable SSL verification;

HTTParty.get( "#{ @settings.api_server }#{ url }", :verify => false ).parsed_response
renier

To make HTTParty always skip SSL cert verification, and not have to specify this in every call:

require 'httparty'
HTTParty::Basement.default_options.update(verify: false)

HTTParty.get("#{@settings.api_ssl_server}#{url1}")
HTTParty.get("#{@settings.api_ssl_server}#{url2}")
HTTParty.get("#{@settings.api_ssl_server}#{url3}")
# ...

You can also do this scoped to a class when including HTTParty as a module:

require 'httparty'

class Client
  include HTTParty
  default_options.update(verify: false)
end

Client.get("#{@settings.api_ssl_server}#{url1}")
Client.get("#{@settings.api_ssl_server}#{url2}")
Client.get("#{@settings.api_ssl_server}#{url3}")

Or

require 'httparty'

module APIHelpers
  class Client
    include HTTParty
    default_options.update(verify: false)
  end
end
World(APIHelpers)

Client.get("#{@settings.api_ssl_server}#{url1}")
Client.get("#{@settings.api_ssl_server}#{url2}")
Client.get("#{@settings.api_ssl_server}#{url3}")

If you want to still send your certificates, use this flag:

verify_peer: false

This may be totally off base, as I'm new to Ruby, but this is what worked for me when other solutions wouldnt

OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!