In practical development, in order to solve the problem of Ajax cross-domain requests, the target's Web API is requested and returned by a controller on the same domain at the server. To facilitate debugging of such requests, we want to be able to monitor these requests through Fiddler. Fiddler official gives the Java application How to configure: Configure a Java application to use Fiddler. But we found that if we use org.apache.http.impl.client.DefaultHttpClient, neither of the official methods is valid (using java.net.HttpURLConnection does not exist).
Initially looked up some information to understand the need for code display settings defaulthttpclient use proxy, as follows:
New Httphost ("127.0.0.1", 8888new defaulthttpclient (); Httpclient.getparams (). Setparameter ( Connroutepnames.default_proxy, PROXY);
By adding the above code, fiddler can actually capture the request, but the code is too intrusive to meet our expectations. So on the Apache website to check the information. Finally found a very useful article: Chapter 2. Connection Management. The HttpClient proxy configuration section mentions a standard JRE proxy that can be set using code (one can also instruct HttpClient to use the standards JRE proxies Sele ctor to obtain proxy information), which means you can use the configuration method mentioned in the Fiddler website. Modify the code as follows:
Newnew Systemdefaultrouteplanner (Proxyselector.getdefault ());
Httpclient.setrouteplanner (Routeplanner);
Fiddler how to capture Defaulthttpclient HTTP requests