I want my Java program to use the system's proxy configuration. Accordingly, I used the code found in many places, such as this answer, to set java.net.useSystemProxies
to true and call ProxySelector.getDefault().select(...)
to discover the proxy for the particular host I want to reach. This works fine when I've configured a single explicit proxy server in Internet Properties. But if I have set "Use automatic configuration script", it always returns the DIRECT "proxy".
I know that the script works, as my browser can access the hosts for which it returns a proxy server, and without the script set, it can't. I even tried simplifying the script to its barest essentials:
function FindProxyForURL(url, host)
{
return "PROXY my.proxy.mydomain:3128";
}
and it works in my browser, but ProxySelector.getDefault().select(...)
still returns only DIRECT.
Am I missing something? (This is on Java 1.6 & Windows 7, should it matter.)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…