Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Without changing code, how to force httpClient to use proxy by environment variables or JVM arguments

I found setting http.proxyHost and http.proxyPort is of no use to httpClient. How to force the httpClient to use proxy by environment variables or VM arguments or something like those without changing code?

like image 895
user496949 Avatar asked Mar 02 '11 08:03

user496949


People also ask

What is Httpclient proxy?

Advertisements. A Proxy server is an intermediary server between the client and the internet.

Does Java use Http_proxy?

Java provides proxy handlers for HTTP, HTTPS, FTP, and SOCKS protocols. A proxy can be defined for each handler as a hostname and port number: http. proxyHost – The hostname of the HTTP proxy server.


2 Answers

in https://issues.apache.org/jira/browse/HTTPCLIENT-1128

SystemDefaultHttpClient was added to ver. 4.2

see http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/impl/client/SystemDefaultHttpClient.html

like image 54
Krystian Nowak Avatar answered Sep 26 '22 01:09

Krystian Nowak


HTTP client (v 4.5.1 for my case) can use system proxy like this:

HttpClient httpClient = HttpClientBuilder.create().useSystemProperties().build(); //or  HttpClient httpClient = HttpClients.createSystem(); 
like image 44
wangf Avatar answered Sep 27 '22 01:09

wangf