2
votes

Im trying to get all http requests that my Java application makes to go through a proxy. Ive set the proxy host and port via system properties

 System.setProperty("http.proxyHost", "192.168.1.23")
 System.setProperty("http.proxyPort", "8081")

The problem I have is that the application will make http requests even if the proxy isnt available. In fact if I put in any non-valid proxy host property Java seems to ignore the proxy setting and connect directly anyway.

Id like to force all http connections to use these proxy settings and fail (via exception) if it cant connect to the proxy. Any ideas for how I can force this behaviour?

Thanks

1

1 Answers

0
votes

I think your program is not referring to the proxy settings at all and hence no errors. I believe in addition to your proxy settings you also need to set the property 'http.proxySet' to true to indicate to the JVM that it has to use the proxy.