How to get proxy settings from system settings in Java

I'm looking for a form on how to get system proxy information in Java under Windows, but I only found one way. But this does not work for me.

public static void main(String[] args) throws Throwable { System.setProperty("java.net.useSystemProxies", "true"); System.out.println("detecting proxies"); List<Proxy> pl = ProxySelector.getDefault().select(new URI("http://ihned.cz/")); for (Proxy p : pl) System.out.println(p); Proxy p = null; if (pl.size() > 0) //uses first one p = pl.get(0); System.out.println(p.address()); System.out.println("Done"); } 

When I run the program, I get:

 detecting proxies DIRECT null Done 

Java means that I am located directly on the Internet. But this is wrong. I am for the proxy. I can not get a solution for my computer.

+8
java proxy networking
source share
2 answers

As we said in the comments, proxy settings apply only to some browsers that you use.

If you want Java to use the same settings, you need to manually place them in the java network settings (for more details, see

+6
source share

Thanks Dacwe. The problem is that the browser does not use the system proxy, but it sets up the proxy server using a script. Thus, there are no proxies in the system, and Java cannot reach them.

+2
source share

All Articles