有没有办法获取java用来连接到互联网的互联网连接设置(代理服务器信息)?
在Java1.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浏览器,它需要这些设置才能开始运行。
发布于 2009-09-14 19:52:38
我在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中找到了它。
论坛帖子的网址是:http://forums.sun.com/thread.jspa?threadID=364342&forumID=30
https://stackoverflow.com/questions/1388057
复制相似问题