开发者

How to get proxy settings from system settings in Java

I'm looking form way how to get system proxy information in Java under Windows, but I've found just one way. But it 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'm situated directly on internet. But it's wrong. I'm behi开发者_如何转开发nd proxy. I'm unable to get the solution for my computer.


As we discussed in the comments the proxy settings is just applied for some of browsers you use.

If you want Java to use the same settings you need to manually put it into the java network settings (check this web page for details).


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜