Why does my proxyHost / proxyPort not work when starting my Java application?

I have a java application that speaks with some REST services and I want to watch HTTP traffic using Fiddler.

Fiddler acts as a proxy on localhost: 8888, so the following Java VM settings must configure java to use this proxy:

-Dhttp.proxyHost=localhost -Dhttp.proxyPort=8888

However, if I pass these parameters when starting the Java application that I want to debug, I do not see traffic in Fiddler.

I wrote a test Java application that just does an HTTP GET using HttpURLConnection.

I can view the HTTP traffic from this application in a script if I specify the above command line options when debugging from Eclipse.

What are the reasons why http.proxyHost / Port might not work for all java http operations?

+5
source share
4 answers

You can tell HttpClient to honor the JDK system arguments using the code below (HttpClient 4.x).

public static final DefaultHttpClient HTTP = new DefaultHttpClient();
ProxySelectorRoutePlanner routePlanner = new ProxySelectorRoutePlanner(HTTP.getConnectionManager().getSchemeRegistry(),
ProxySelector.getDefault());
HTTP.setRoutePlanner(routePlanner);
+4
source

In 4.3.6 I used

HttpHost proxy = new HttpHost(System.getProperty("http.proxyHost"), Integer.parseInt(System.getProperty("http.proxyPort")), "http");//System.getProperty("http.proxyHost")
DefaultRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy);
CloseableHttpClient httpClient = HttpClients.custom().setRoutePlanner(routePlanner).build();
+2
source

, - :

 CloseableHttpClient httpClient = HttpClients.custom()
   .setRoutePlanner(new SystemDefaultRoutePlanner(ProxySelector.getDefault())

.

TL; DR - :

-Dhttp.proxyHost = localhost -Dhttp.proxyPort = 8888 -Dhttp.nonProxyHosts =

:

:

"localhost", . , .

, HTTP- HTTP-. (, , , JDeveloper ). Java 6737819. JDK 1.6 , localhost -, , , . , , "~ localhost" nonProxyHosts :

java -client -classpath classes 
-Dhttp.proxyHost=localhost 
-Dhttp.proxyPort=8099 -Dhttp.nonProxyHosts=~localhost 
-Dhttps.proxyHost=localhost 
-Dhttps.proxyPort=8099 client.Example 

, JDK 1.7, ; , nonProxyHosts :

java -client -classpath classes 
-Dhttp.proxyHost=localhost 
-Dhttp.proxyPort=8099 
-Dhttp.nonProxyHosts= 
-Dhttps.proxyHost=localhost 
-Dhttps.proxyPort=8099 client.Example  

, , DefaultProxySelector, , / http.nonProxyHosts .. /jre/lib/net.properties ".

, API.

+1

Apache httpclient 4.3.6 , SystemDefaultRoutePlanner.

SystemDefaultRoutePlanner routePlanner = new SystemDefaultRoutePlanner(null);
CloseableHttpClient httpClient = HttpClientBuilder.create()
  .setRoutePlanner(routePlanner)
  .build();

- http.proxyHost http.proxyPort HTTP-.

0
source

All Articles