I try this code, but when the proxy is too slow I get connection timed out error. How can I solve this? I tried Exception handling but doesn't work. Can anybody help?
Net::HTTP.new('example.com', nil, '140.113.182.81', '808').start { |http|
begin
response = http.request
p response
rescue Timeout::Error
p 'timed out'
end
}
The Timeout::Error is raised by the Net::HTTP.connect
method that is executed by start
, not by request
.
It means that in order to rescue the timeout, the whole Net::HTTP
call should be inside the begin block.
begin
Net::HTTP.new('example.com', nil, '140.113.182.81', '808').start do |http|
response = http.request
p response
end
rescue Timeout::Error
p 'timed out'
end
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments