系统代理设置,Java [英] System proxy setting, Java

查看:44
本文介绍了系统代理设置,Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要连接到网络的应用程序.在处理代理连接时,我需要一些建议.目前用户设置了代理设置,因此我使用输入的信息进行连接.有没有更好的方法来处理这种情况.

I have an application which needs to connect to net. I need some advice when dealing with proxy Connections. Currently the user sets the proxy settings and hence I use the entered information to connect. Is there a better way to deal with such situations.

我的意思是像 chrome 这样的东西,它会打开系统的代理设置,然后使用它们.如何做到这一点并检索这些值?还有其他理想的方法吗?

I mean something like chrome which opens system's proxy settings and then uses them. How to do it and retrieve those values? Any other Ideal method?

其次,目前我正在检查是否设置了代理.如果是,我正在使用 url.openConnection(proxy);如果不是那么简单 url.openConnection(); 有没有更简洁的方法呢?系统自动连接代理设置.

Secondly, currently I am checking if there is a proxy set or not. If yes, I am using url.openConnection(proxy); IF not then plain url.openConnection(); Is there a more cleaner way of doing it? where system automatically connects with proxy set.

推荐答案

从源代码我们可以使用

From source code we can use

System.getProperties().put("http.proxyHost", "ProxyURL");
System.getProperties().put("http.proxyPort", "ProxyPort");
System.getProperties().put("http.proxyUser", "UserName");
System.getProperties().put("http.proxyPassword", "Password");

命令行:

  $> java -Dhttp.proxyHost=proxyhostURL -Dhttp.proxyPort=proxyPortNumber
-Dhttp.proxyUser=UserName -Dhttp.proxyPassword=Password ProxyClassHere

文档

这篇关于系统代理设置,Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆