/** * 根据指定的代理信息设置系统全局的网络代理 * * @param networkBean */ public static void setNetworkProxyBySystem(NetworkBean networkBean) { System.out.println("System Set Proxy : " + networkBean); if (isUserProxy(networkBean)) { if (networkBean.getType() == Proxy.Type.SOCKS) { System.getProperties().remove("http.proxyHost"); System.getProperties().remove("http.proxyPort"); System.getProperties().setProperty("socksProxyHost", networkBean.getAddress()); System.getProperties().setProperty("socksProxyPort", networkBean.getPort()); } else { System.getProperties().setProperty("http.proxyHost", networkBean.getAddress()); System.getProperties().setProperty("http.proxyPort", networkBean.getPort()); } Authenticator.setDefault(new BairuiAuthenticator(networkBean.getDomainAndUsername(), networkBean.getPassword())); } else if (networkBean != null) { System.getProperties().remove("proxySet"); System.getProperties().remove("socksProxySet"); System.getProperties().remove("http.proxyHost"); System.getProperties().remove("http.proxyPort"); System.getProperties().remove("socksProxyHost"); System.getProperties().remove("socksProxyPort"); } }