Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
&引用;“适当的”;Java中(web)代理的实现方法_Java_Http_Proxy - Fatal编程技术网

&引用;“适当的”;Java中(web)代理的实现方法

&引用;“适当的”;Java中(web)代理的实现方法,java,http,proxy,Java,Http,Proxy,到目前为止,我的研究发现了四种让Java使用代理的不同方法: 命令行参数,如-Dhttp.proxyHost 系统属性,如System.getProperties().put(“http.proxyHost”、“110.11.12.30”) URLConnection(代理) urlConnection.setRequestProperty( 哪一种是指定代理的正确/推荐方法(忽略可能使一种方法比其他方法更具吸引力的特定外部要求)?如果您想依赖Java的URLConnecion,我会选择选项

到目前为止,我的研究发现了四种让Java使用代理的不同方法:

  • 命令行参数,如-Dhttp.proxyHost
  • 系统属性,如System.getProperties().put(“http.proxyHost”、“110.11.12.30”)
  • URLConnection(代理)
  • urlConnection.setRequestProperty(

哪一种是指定代理的正确/推荐方法(忽略可能使一种方法比其他方法更具吸引力的特定外部要求)?

如果您想依赖Java的URLConnecion,我会选择选项三。

还有一个系统属性可以从系统继承代理设置:

-Djava.net.useSystemProxies=true

我最喜欢绿色。你能解释或支持你的建议吗?是的,这个选项让我可以完全灵活地控制代理设置。选项一和选项二总是更改整个虚拟机,这在Tomcat使用的共享虚拟机中可能不需要。选项四我不知道。从什么时候开始,我可以将代理设置为请求属性?选项四这很奇怪。