The people who do web development always avoid to deal with HTTP/HTTPS request, many times we all want to be able to visually see the request parameter that we send and the response information that the server returns, this time need to rely on some tools. This article will use Fiddler2 as an analysis tool, Fiddler is very powerful, it can record all the client and server HTTP and HTTPS requests, allowing you to monitor, set breakpoints, and even modify the input and output data, is the wall grasping the package of the weapon. For a description of the tool, refer to the following link:
Http://www.cnblogs.com/TankXiao/archive/2012/02/06/2337728.html
The interface of the tool is as follows (copy the above linked diagram):
Here, I would like to note the following points:
1, the principle of the tool is actually started when you opened a proxy (port is 8888, the default), when the shutdown will cancel the proxy settings. As shown, then all requests are first passed through this agent (except localhost), so it supports a variety of browsers.
2, the default is not to open the HTTPS request monitoring, so you have to manually open, tick the red box below the thing, pay attention to that paragraph of red words OH
1. Background Works HTTP request
By default, Fiddler cannot listen for Java httpurlconnection requests. The reason is that the Java Network Communication protocol stack may be slightly different from the browser's communication protocol stack, the principle of Fiddler listening HTTP request is to build a proxy server between the application and the operating system network communication layer. Java's httpurlconnection should have bypassed the proxy server, so fiddler could not hear the Java httpurlconnection request. The workaround is to set a proxy for the Java environment to point to Fiddler, which has two methods:
One is to set the JVM's startup parameters, and MyApp is your application name
java-dproxyset=true-dproxyhost=127.0.0.1-dproxyport=8888 MyApp
Second, set the environment properties
System.setproperty ("Http.proxyhost", "localhost"); System.setproperty ("Http.proxyport", "8888"); System.setproperty ("https.proxyhost", "localhost"); System.setproperty ("Https.proxyport", "8888");
2, the background works HTTPS request
This is more cumbersome, the whole of a long time to understand, the main difficulty is the HTTPS certificate problem, the relevant knowledge can refer to the following link: http://www.cnblogs.com/devinzhang/archive/2012/02/28/2371631.html.
We know that the SDK to send HTTPS requests must first register the certificate of the site to the JRE, the method of registration is as follows:
Where Keytool is located in the Java JDK Bin directory.
To listen to a background HTTPS request, you must register two certificates, one for the HTTPS site, and one for Fiddler's own certificate. Remember the first piece of red text above? Yes, click that button to export the certificate to the desktop. After registering the certificate for the HTTPS site, register the fiddler certificate. Then follow the above method to register the certificate, the following is the registration code of my Machine
C:\users\administrator>d:\bingoeclipse4.3win64\jdk\bin\keytool.exe-import--keystore FiddlerKeystore -Aliasfiddler
Please remember to register two certificates, otherwise there will be no error reporting the certificate.
After the above certificate registration, we should be able to implement monitoring HTTPS requests, but there is a problem, that is the previous mentioned fiddler will ignore the request of localhost, so we still want to configure a proxy point to fiddler, The following information is configured where the JVM's startup parameters are:
I use the Intell idea Editor, Eclipse is only the configuration of the place is different, personal feeling idea is more useful, smart tips are strong.
After the above configuration and registration processing, now running should be able to listen to HTTPS requests, as follows.
Now the boss no longer have to worry about my request, where not to point where ...