I have a java app that talks to some REST services, and I want to look at the HTTP traffic using Fiddler.
Fiddler acts as a proxy on localhost:8888, so the following Java VM options are supposed to configure java to use this proxy:
-Dhttp.proxyHost=localhost -Dhttp.proxyPort=8888
However, if I pass these parameters when running the java app that I want to debug, I see no traffic in Fiddler.
I wrote a test Java app that simply performs an HTTP GET using HttpURLConnection.
I can view the HTTP traffic from this app in fiddler, if I specify the above-mentioned command-line parameters when debugging it from Eclipse.
What are the reasons that http.proxyHost/Port might not work for all java HTTP operations?
解决方案
You can tell HttpClient to honor the JDK system arguments using the below code (HttpClient 4.x).
public static final DefaultHttpClient HTTP = new DefaultHttpClient();
ProxySelectorRoutePlanner routePlanner = new ProxySelectorRoutePlanner(HTTP.getConnectionManager().getSchemeRegistry(),
ProxySelector.getDefault());
HTTP.setRoutePlanner(routePlanner);