在访问网络前调用setProxy , 访问后也可以清除设置的代理。
/**
* プロキシサーバーを設定行う
*
* @param strFunName 外部機能名称
*/
public static void setProxy(String strFunName, String ipAddress) {
// http proxy
System.setProperty("http.proxySet", "true");
System.setProperty("http.proxyHost", ipAddress);
System.setProperty("http.proxyPort", "8080");
System.setProperty("http.proxyUserName", "userName");
System.setProperty("http.proxyPassword", "password");
// https proxy
System.setProperty("https.proxyHost", ipAddress);
System.setProperty("https.proxyPort", "8080");
System.setProperty("https.proxyUserName", "userName");
System.setProperty("https.proxyPassword", "password");
// socks proxy
System.setProperty("socksProxySet", "true");
System.setProperty("socksProxyHost", ipAddress);
System.setProperty("socksProxyPort", "1080");
}
/**
* プロキシを設定解除行う
*
*/
public static void clearProxy() {
// http proxy
System.clearProperty("http.proxySet");
System.clearProperty("http.proxyHost");
System.clearProperty("http.proxyPort");
System.clearProperty("http.proxyUserName");
System.clearProperty("http.proxyPassword");
// https proxy
System.clearProperty("https.proxyHost");
System.clearProperty("https.proxyPort");
System.clearProperty("https.proxyUserName");
System.clearProperty("https.proxyPassword");
// socks proxy
System.clearProperty("socksProxySet");
System.clearProperty("socksProxyHost");
System.clearProperty("socksProxyPort");
}