问题
Does the socksProxyHost property require an IP address?
System.setProperty("socksProxyHost", preferences.getProxyHost() );
Setting it like above, if I provide 127.0.0.1, I get connected to the proxy on my localhost. But if I provide localhost, it does not connect it. I have no other machines on the LAN I can use to this. So does anyone know if it works with hosts names or do I have to resolve the host and pass in an IP?
回答1:
System properties are just a dumb map. There are no observers to be notified when a value changes. It is normal to read a value just once and store it in a private static final
, rather than looking the value up every time that it is needed.
Probably the relevant code is initialised whilst loading your application, so the value has already been read. A quick look at the API docs shows a promising method to call to change the default proxy: ProxySelector.setDefault.
来源:https://stackoverflow.com/questions/948535/java-socks-proxy