How do I make HTTParty ignore SSL?

前端 未结 4 494
醉梦人生
醉梦人生 2020-12-05 17:08

I\'m using a local server to test an application, and make requests to that server from my own machine.

The test server\'s SSL is bad, and HTTParty throws errors bec

相关标签:
4条回答
  • 2020-12-05 17:28

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

    verify_peer: false
    
    0 讨论(0)
  • 2020-12-05 17:34

    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}")
    
    0 讨论(0)
  • 2020-12-05 17:35

    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
    

    Additional ways of doing this, if you get a 'dynamic constant assignment' (pulled from here)

    OpenSSL::SSL.const_set(:VERIFY_PEER, OpenSSL::SSL::VERIFY_NONE) 
    
    0 讨论(0)
  • 2020-12-05 17:41

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

    HTTParty.get( "#{ @settings.api_server }#{ url }", :verify => false ).parsed_response
    
    0 讨论(0)
提交回复
热议问题