The*_*aul 9 java proxy http apache-commons
如果应用程序使用java.net.*例程,我可以在调用应用程序时设置代理,如下所示:
java -Dhttp.proxyHost=proxy.server.com -Dhttp.proxyPort=8000 <whatever-the-app-is>
Run Code Online (Sandbox Code Playgroud)
但是,我有一个应用程序(我无法更改)使用org.apache.commons.httpclient来进行http通信.它没有指定procxy服务器,但它确实使用默认的HttpConnection.有什么方法可以从命令行告诉apache http客户端使用代理服务器吗?
使用HTTPClient构建器时,使用useSystemProperties()方法启用标准JVM -D代理参数.
请参阅http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/impl/client/HttpClientBuilder.html#useSystemProperties()
例:
CloseableHttpClient httpclient = HttpClients.custom()
.useSystemProperties()
.build();
Run Code Online (Sandbox Code Playgroud)
现在使用-Dhttp.proxyHost = 10.0.0.100 -Dhttp.proxyPort = 8800来配置代理.