zoukankan      html  css  js  c++  java
  • 为java程序配置网络访问代理

    在访问网络前调用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");
    	}
    

      

  • 相关阅读:
    js正则表达语法
    Codeforces 976E/925C (01Trie树)
    ZOJ 3879(大模拟)
    CF967C(二分+细节)
    CF967A(细节模拟)
    HDU 2222(AC自动机模板)
    HDU 5510(KMP+思维)
    HDU 6273(树状数组+思维)
    HDU 6266(思维+规律)
    HDU 6264(思维)
  • 原文地址:https://www.cnblogs.com/wzihan/p/14109480.html
Copyright © 2011-2022 走看看