如何在java代码中设置代理配置
我正在尝试用 Java 编写一个类来启动我的 Selenium 服务器,以防它因某种原因关闭。我在这里找到了非常好的帮助: http://www .testingexcellence.com/how-to-start-selenium-server-with-java-code/
我看到一些配置参数是否可以使用类 RemoteControlConfiguration 和方法来设置as setPort, setLogOutFileName, setTimeoutInSeconds, ...
问题是我的 Selenium Server 以这种方式连接到代理:
java -jar selenium-server.jar -Dhttp.proxyHost=my.proxy.com -Dhttp.proxyPort=8080
不幸的是,我还没有找到如何将其放入 java 代码中。我的问题是:是否可以在java中设置proxyHost和proxyPort值?
感谢您抽出时间 =)
}万能药{
I'm trying to program in Java a class to start my Selenium Server in case it is down for some reason. I found very good help here: http://www.testingexcellence.com/how-to-start-selenium-server-with-java-code/
I see that some if the configuration parameters can be set using the class RemoteControlConfiguration and methods such as setPort, setLogOutFileName, setTimeoutInSeconds, ...
The problem is that my Selenium Server connects to a proxy in this way:
java -jar selenium-server.jar -Dhttp.proxyHost=my.proxy.com -Dhttp.proxyPort=8080
Unfortunately, I haven't found how to put this into java code. My question is: Is it possible to set the proxyHost and proxyPort values in java?
Thanks for your time =)
}Panacea{
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最简单的方法可能就是在 JVM 中全局设置它们
http://download.oracle.com/javase/6/docs/technotes/guides/net/proxies.html
但是,这会影响 JVM 的整个实例,因此任何其他传出连接也会尝试使用代理人。对于您的情况来说这可能没问题,但如果您需要更独立的范围,您可以使用 URL.openConnection(Proxy)。
http ://download.oracle.com/javase/1.5.0/docs/api/java/net/URL.html#openConnection%28java.net.Proxy%29
The easiest way is probably just to set them globally within the JVM
http://download.oracle.com/javase/6/docs/technotes/guides/net/proxies.html
However this affects that entire instance of the JVM, so any other outgoing connections will also try to use the proxy. That's probably fine in your case, but if you need more isolated scope you can use URL.openConnection(Proxy).
http://download.oracle.com/javase/1.5.0/docs/api/java/net/URL.html#openConnection%28java.net.Proxy%29
您应该能够对每个属性名称和值使用 java.lang.System.setProperty(String, String) 。
You should be able to use
java.lang.System.setProperty(String, String)
for each property name and value.