2009-09-07 31 views
1

有沒有辦法讓java連接到互聯網時使用互聯網連接設置(代理信息)?閱讀Java互聯網連接設置 - jdk1.4

隨着Java 1.5的你可以使用ProxySelector介紹然後,有沒有辦法在jdk1.4做到這一點?

我試過使用下面的代碼片段獲得這些seeting,但即使設置了我的代理也返回null。

String javaVersion = System.getProperty("java.version"); 
String ip = null; 
String port = null; 
String noProxyHosts = null; 

if (javaVersion.startsWith("1.4")) { 
    ip = System.getProperty("proxyHost"); 
    port = System.getProperty("proxyPort"); 
    noProxyHosts = System.getProperty("http.nonProxyHosts"); 
} else { 
    ip = System.getProperty("deployment.proxy.http.host"); 
    port = System.getProperty("deployment.proxy.http.port"); 
    noProxyHosts = System.getProperty("deployment.proxy.override.hosts"); 
} 

簡要背景;我有一個webstart Java應用程序,它生成一個內部Web瀏覽器,需要這些設置才能開始。

回答

1

我發現在Java論壇此代碼示例:

sun.plugin.net.proxy.ProxyInfo pi = sun.plugin.net.proxy.PluginProxyManager.getProxyInfo(url); 
    String host = pi.getProxy(); 
    int port = pi.getPort(); 

您需要plugin.jar添加到類路徑使用此代碼。我在/ jre/lib中找到它。

論壇帖子的URL是:http://forums.sun.com/thread.jspa?threadID=364342&forumID=30

+0

我發現代碼段真的很有幫助。 http://forums.sun.com/thread.jspa?messageID=1535962#1535962 – n002213f 2009-09-15 05:10:17