How to make HTTParty ignore SSL?

I use a local server to test the application and send requests to this server from my own machine.

The SSL test server protocol is bad, and HTTParty throws errors because of this. From what I read, HTTParty should ignore SSL by default, but when I try to do this:

HTTParty.get( "#{ @settings.api_server }#{ url }" ).parsed_response 

It throws this error:

 OpenSSL::SSL::SSLError at / SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed 

How do I get to ignore SSL?

+47
ruby ssl
Jan 6 '14 at 17:01
source share
4 answers

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

 HTTParty.get( "#{ @settings.api_server }#{ url }", :verify => false ).parsed_response 
+52
Mar 27 '14 at 18:01
source

So that HTTParty always skips SSL certificate verification, and you do not need to indicate this with 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 for the class when you include 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}") 
+25
Sep 17 '14 at 22:37
source

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

 verify_peer: false 
+3
Oct 31 '16 at 9:50
source

It may be completely wrong, since I'm new to Ruby, but this is what worked for me when other solutions fail

 OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE 
0
Apr 29 '19 at 14:17
source



All Articles