I need an application to block an HTTP request so I had to add a couple of lines of code, the only piece I couldn't figure out was the statement if uri.scheme == 'https'; http.use_ssl = true
is there a way I can set http/https in the current statement:
Net::HTTP.new(uri.host, uri.port).start do |http|
# Causes and IOError...
if uri.scheme == 'https'
http.use_ssl = true
end
request = Net::HTTP::Get.new(uri.request_uri)
http.request(request)
end
Added: IOError: use_ssl value changed, but session already started
Per the documentation, you cannot call use_ssl=
after starting the session (i.e. after start
). You have to set it before, e.g.:
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true if uri.scheme == 'https'
http.start do |h|
h.request Net::HTTP::Get.new(uri.request_uri)
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With