Fiddler how to capture Defaulthttpclient HTTP requests

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.