I have code to check the proxy server and port, some of these characters:
System.getProperties().put("proxySet", "true"); System.getProperties().put("https.proxyHost", "localhost"); System.getProperties().put("https.proxyPort", "1234"); System.getProperties().put("http.proxyHost", "localhost"); System.getProperties().put("http.proxyPort", "1234"); HttpURLConnection conn = (HttpURLConnection) new URL("https://www.google.com").openConnection(); conn.getContent(); conn.disconnect();
it seems that the openConnection () method will do the following:
- try connecting this url using a proxy server.
- If he cannot use the proxy server, he will directly bind the URL without a proxy server .
that is the problem, I wanted to check if the proxy server is working, but this code will not stop if the proxy server cannot connect.
I also tried using the isReachable () method of the InetAddress class, but I get the same result.
so how can I stop this connection if the proxy server is down to check if the proxy is available?
source share